I am a beginning at programming and need to know what I am doing wrong with this code. I keep getting error codes on undeclared variables, storage types, etc.
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
const int ARRAY_SIZE = 100;
void InputData(string, int[], int &);
void DisplayPlayerData(const string, const int[], int);
double CalculateAverageScore(const int[], int);
void DisplayBelowAverage( const string; const int[]; int, double);
void main()
{
//Declare the player name and score arrays, number of players, and average score.
string playerNameAr[ARRAY_SIZE];
int scoreAr[ARRAY_SIZE];
int numPlayersAr = 0;
double averageScore;
cout << fixed << showpoint << setprecision(2);
//Call the InputData function
InputData(playerNameAr, scoreAr, numPlayersAr);
//Call the DisplayPlayerData function
DisplayPlayerData(playerNameAr, scoreAr, numPlayersAr);
//Call the CalculateAverageScore function and assign the returned value in average score
CalculateAverageScore(scoreAr, numPlayersAr);
//Call the DisplayBelowAverage function
DisplayBelowAverage(playerNameAr, scoreAr, numPlayersAr, averageScore);
}
void InputData(playerNameAr[], scoreAr[], numPlayersAr);
{
while(numPlayersRef < ARRAY_SIZE)
{
//Prompt for the player's name or Q to quit
cout << "Enter the player's name (Q to quit). " << endl;
getline (cin, playerNameAr[numPlayersRef]);
if (playerNameAr[numPlayersRef] == "Q") break;
//Prompt the user for the player's score
cout << "Enter the player's score. " << endl;
cin >> scoreAr[i];
//Add 1 to the number of players
numPlayersRef++;
}
}
void DisplayPlayerData(playerNameAr[], scoreAr[], numPlayers)
{
cout << setw(10) << left << "\n Name"
<< setw(5) << right << "Score" << endl;
for(int i = 0; i < numPlayers; i++)
{
//Display the name and score of each player
cout << "The players name is: " << playerNameAr[i] << endl;
cout << "The players score is: " << scoreAr[i] << endl;
i++;
}
}
double CalculateAverageScore(scoreAr[], numPlayers)
{
int i;
double averageScore, totalScore;
for(i = 0, totalScore = 0; i < numPlayers; i++)
{
//Add up the scores
totalScore += scoreAr[i];
}
//divide by the number of scores to calculate the average score
averageScore = totalScore / numPlayers;
//Display the average score
cout << "Average score is ." << averageScore << endl;
//Return the average score to main
return averageScore;
}
void DisplayBelowAverage(playerNameAr[], scoreAr[], numPlayers, averageScore)
{
cout << "Players who scored below average\n";
cout << setw(10) << left << " Name" << setw(5) << right << "Score" << endl;
for(int i = 0; i < numPlayers; i++)
if(scoreAr[i] < averageScore)
//Display the names and scores of all players who scored below the average score
cout << setw(10) << left << playerNameAr[i] << setw(5) << right << scoreAr[i] << endl;
}