i have a problem getting it to display the average score of the players entered and also the player names and their scores for those that scored below the average. it works other than that. its late, ive been at this and another program for hours im probably not thinking straight anymore. any help would be great

#include <iostream>
#include<string>
#include<iomanip>

using namespace std;

int inputData(char[][50], int[], int&, int&);
int displayData(char[][50], int[], int);

int main() 

{

 
char playerName[100][50] = {0}; 
int score[100] = {0}; 
int average;
int belowAverage = 0; 
int numPlayers = 0;

 
inputData(playerName, score, numPlayers, average);
displayData(playerName, score, numPlayers);
cout << "\n\nAverage Score: " << average << endl;
cout << "\n\nPlayers who scored below the average: " << belowAverage << endl;

}

 
int inputData(char playerName[][50], int score[100], int &numPlayers, int &average) 

{

 while(numPlayers < 100) 

{

cout <<" Enter Players Name(Q to quit) :"; 
cin >> playerName[numPlayers];
if(playerName[numPlayers][0] == 'q' || playerName[numPlayers][0] == 'Q')
break;
 
cout << "Enter score:"; 
cin >> score[numPlayers];
numPlayers += 1;
average += score[numPlayers];
}
 
int belowAverage[50] = {0};
average = average / numPlayers;


for(int i = 0; i < average; i++)

{
 belowAverage[i]= average;


}
if(score[numPlayers] < average)


score = belowAverage;


return 0; 

}


int displayData(char playerName[][50], int score[100], int numPlayers) 

{
for(int index = 0; index < numPlayers; index++) 

{

cout << "\nPlayer Name: " << playerName[index] << endl; 
cout << "Score: " << score[index] << endl;



}

 


return 0; 

}

I would definitely suggest using a std::vector<std::string> to store the player names. Also, if you hard code an example input that will eliminate one source of errors (the input). It will also let us copy/paste/compile/run your code to help you find the problems. It is much harder when you have to also give us an input file and we have to confirm your input function works, etc.

everything but lines 24 and 25 work right 100%. take those two lines out and it works..just trying to add the rest in to get it to display the average score of the players and those players that scored lower than the average.

The goal shouldn't be to get this to work, it should be to learn something :)

I would separate the averaging computation from the input. There should be a inputData() and a computeAverage() . This will help you track down the error, as well as help the next reader of your code follow what is going on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.