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;
		}
	}
}

As it says you have a double function so it is expecting a double value to be returned.

Plus you seem to be missing some function definitions.

Edited 5 Years Ago by frogboy77: n/a

Here is the correct code fixed:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int InputData(string [], int []);
void DisplayPlayerData( string [], int [], int );
int CalculateAverageScore( int [], int ); 
void DisplayBelowAverage( string [], int [], int, int );

int main()
{
	string players[100];
    int score[100];
    int numPlayers = 0;
    int averageScore = 0;

    numPlayers = InputData (players, score);
      
    //
    // Display the players and their scores
    //
    DisplayPlayerData( players, score, numPlayers );

    //
    // Call CalculateAverageScore() which returns thre score average as an integer
    // Note that we only pass the variables we actually need in the function - not the ones we do not need
    //
    averageScore = CalculateAverageScore( score, numPlayers );

    //
    // Display the below average scores
    //
    DisplayBelowAverage( players, score, numPlayers, averageScore );

    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
//
int CalculateAverageScore( int score[], int numPlayers )
{
	int 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:  " << (float)scoreTotals / (float)numPlayers << endl;
	return scoreTotals / numPlayers;
}


// 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;
		}
	}
}
This article has been dead for over six months. Start a new discussion instead.