I'm having trouble getting the player's name and score to display as well as the average score. I have been at this for about 3 hours. I think it's time for a fresh set of eyes. Can someone please help?! This assignment is due tomorrow. Thanks
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//prototypes
int inputData(string[], int[], int);
void displayData(string[], int[], int);
int calculateAverageScore(int [], int, int);
void displayBelowAverage(string[], int[], int, int);
int main()
{
string playerName[100];
int playerScore[100];
int average = 0;
int numOfPlayers = 0;
//call functions
inputData (playerName, playerScore, numOfPlayers);
displayData(playerName, playerScore, numOfPlayers);
calculateAverageScore(playerScore, numOfPlayers, average);
displayBelowAverage(playerName, playerScore, numOfPlayers, average);
return 0;
}
int inputData(string playerName[], int playerScore[], int numOfPlayers)
{
for (int i = 0; i < 100; i++)
{
cout << "Enter player's name (Q to quit): ";
getline(cin, playerName[i], '\n');
if ((playerName[i] == "Q") || (playerName[i] == "q"))
{
return i;
}
cout << "Enter score for " << playerName[i] << ": ";
cin >> playerScore[i];
cin.ignore();
numOfPlayers += 1;
}// end while
}
void displayData(string playerName[], int playerScore[], int numOfPlayers)
{
cout << " Name Score " << endl << endl;
for (int i = 0; i < numOfPlayers; i++)
{
cout << playerName[i] << " " << playerScore[i] << endl;
}
}
int calculateAverageScore(int playerScore[], int numOfPlayers, int average)
{
for (int i = 0; i < numOfPlayers; i++)
{
average += playerScore[i];
average = average / numOfPlayers;
}
cout << endl << "Average Score: " << average << endl;
return average;
}
void displayBelowAverage(string playerName[], int playerScore[], int numOfPlayers, int average)
{
int belowAverage = 0;
cout <<endl << "Players that scored below average" << endl << " Name Score" << endl;
for (int i = 0; i < average; i++)
{
if (playerScore[i] < average)
playerScore[i] = belowAverage;
{
cout << playerName[i] << " " << playerScore[i] << endl << endl;
}
}
}
I'm also getting this warning message: 1>c:\users\nika\documents\visual studio 2008\projects\lab5a\lab5a\lab5a.cpp(55) : warning C4715: 'inputData' : not all control paths return a value.