Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (lucinda):

need help debugging. This is where my errors start. return sum/howManyPlayers; } void displayBelowAverage(string names[], int scores[]); { double average =0.0; average = calculateAverageScore(scores,howManyPlayers); for (int k = 0; k < howManyPlayers; k++) { if (scores[k] < average) { cout << names[k] << "\t\t" << scores[k] << endl; } } return; }

OpenStudy (bibby):

a) attach the cpp files next time b) we need the errors

OpenStudy (bibby):

first problems I see with your code: your includes have semicolons at the end. they're of the format #include <cmath>

OpenStudy (bibby):

main function must return an int. the main method follows the pattern int main() { return 0; } line 50: there are 3 minuses in your decrement operation. line 73: return sum/howManyPlayers is dividing a double by an int ARRAY.

OpenStudy (kainui):

Also, at the top left of your keyboard there's this symbol ` use it to make code by typing it three times to begin a block and end a block like this: ``` public static int number =8; prettyColors("Super Cool Yo"); ``` Yeah.

OpenStudy (bibby):

``` #include <iostream> #include <string> //Prototype all functions. double calculateAverageScore(int scores[],int numberOfPlayers); void displayPlayerData(std::string names[], int scores[],int numberOfPlayers); void displayBelowAverage(std::string names[], int scores[], int numberOfPlayers); int inputData(std::string names[], int scores[]); int main() { std::string playerNames[100]; int scores[100]; int numberOfPlayers = inputData(playerNames, scores); std::cout << "\n\nListing of players and their scores\n"; displayPlayerData(playerNames, scores,numberOfPlayers); std::cout << "\nAverage Score: " << calculateAverageScore(scores,numberOfPlayers) << "\n\n"; std::cout << "\n\nListing of players with below avg scores\n"; displayBelowAverage(playerNames, scores, numberOfPlayers); return 0; } double calculateAverageScore(int scores[],int numberOfPlayers) { double sum = 0.0; for (int i=0;i<numberOfPlayers;i++) sum += scores[i]; return (sum/numberOfPlayers); } void displayPlayerData(std::string names[],int scores[],int numberOfPlayers) { for(int i=0;i<numberOfPlayers;++i) std::cout << '\t' << names[i] << '\t' << scores[i] << std::endl; } void displayBelowAverage(std::string names[],int scores[],int numberOfPlayers) { double average = calculateAverageScore(scores,numberOfPlayers); for (int i=0;i<numberOfPlayers;i++) { if(scores[i] < average) std::cout << '\t' << names[i] << '\t' << scores[i] << std::endl; } } int inputData(std::string names[], int scores[]) { int numberOfPlayers = 0; std::cout << "q to quit\n\n"; std::cout << "enter name\n"; std::cin >> names[0]; if(names[0] == "q") return 0; std::cout << "enter score for " << names[0] << "\n"; std::cin >> scores[0]; while(numberOfPlayers<100 && names[numberOfPlayers] != "q") { numberOfPlayers++; std::cout << "Enter player name (Q to quit): "; std::cin >> names[numberOfPlayers]; if(names[numberOfPlayers]=="q") { //numberOfPlayers--; unnecessary because we increment at the start of the while loop break; } else { std::cout << "Enter score for " << names[numberOfPlayers] << ": "; std::cin >> scores[numberOfPlayers]; } } return numberOfPlayers; } ``` I could have just written the pseudocode but meh. comment/refactor as you will. it's mostly your code anyways example of it running: ``` q to quit enter name harry enter score for harry 38 Enter player name (Q to quit): mark Enter score for mark: 86 Enter player name (Q to quit): q Listing of players and their scores harry 38 mark 86 Average Score: 62 Listing of players with below avg scores harry 38 Process returned 0 (0x0) execution time : 11.689 s Press any key to continue. ```

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!