Im getting this error and I am so new at this that I have no idea how to correct it.
If someone has any suggestions.
Programming for 10 weeks!
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int InputData(string [], int []);
int main()
{
string players[99];
int score[99];
int numPlayers = 0;
double averageScore = 0;
numPlayers = InputData (players, score);
for (int i = 0; i < numPlayers; i++)
{
cout << players[i] << ": " << score[i] << endl;
}
return 0;
}
int InputData(string playerName[], int score[])
{
for (int i = 0; i < 100; i++)
{
cout << "Enter the players name (Q to quit): ";
getline(cin, playerName[i], '\n');
if ((playerName[i] == "Q") || (playerName[i] =="q"))
{
return i;
}
cout << "Enter the score of the player " << playerName[i] << ": ";
cin >> score[i];
cin.ignore();
}
}
void DisplayPlayerData( string playerName[], int score[], int numPlayers )
{
// Display the output header column names
cout << " Name Score" << endl;
// Loop through all the players in the array and print their name and score
for (int i = 0; i < numPlayers; i++)
{
cout << playerName[i] << " " << score[i] << endl;
}
}
// Calculate Average Score
// Returns: the average score as an integer
//
double CalculateAverageScore( int score[], int numPlayers )
{
double scoreTotals = 0;
// Loop through all the players in the array and print their name and score
for (int i = 0; i < numPlayers; i++)
{
scoreTotals += score[i]; // Sum up the total scores and keep them in the running value of scoreTotals
}
// Display the Average Score which is the total sum of scores divided by the number of players
cout << endl << "Average Score: " << scoreTotals / numPlayers << endl;
}
//
// Display Below Average scores
// Returns: nothing (void)
//
void DisplayBelowAverage( string playerName[], int score[], int numPlayers, int averageScore )
{
// Display the output header column names
cout << endl << "Players that scored below average" << endl << " Name Score" << endl;
// Loop through all the players in the array and conditionally print their name and below saverage score
for (int i = 0; i < numPlayers; i++)
{
if( score[i] < averageScore )
{
cout << playerName[i] << " " << score[i] << endl;
}
}
}