Need Help with a C++ program I have written

Hello everyone. I have written the program below and I get no errors but for whatever reason my Function (Display below average) is not printing any output. Does anyone have any suggestions? Thanks in advance for your help!

//-------------------------------------------------
//Programming Assignment: LAB5A
//Developer:              Hollis R Burks
//Date Written:           2-7-14
//Purpose:                Video Game Player Program
//-------------------------------------------------

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

using namespace std;

// Function's proto-types
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef);
void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers);
double CalculateAverageScore(const int scoreAr[], int numPlayers);
void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double averageScore);


// constants
const int array_size=100;
string playerNameAr[array_size];
int numPlayers = 0;
int scoreAr[array_size];
double averageScore;




//main Body code
int main()
{cout << fixed << showpoint << setprecision(2);
	//Call the inputData function
	InputData(playerNameAr,scoreAr, numPlayers);
	
	//Call the DisplayPlayerData function
	DisplayPlayerData(playerNameAr,scoreAr, numPlayers);

	//Call the CalculateAverageScore function and assign the returned value in average score
	CalculateAverageScore(scoreAr, numPlayers);

	//Call the DisplayBelowAverage function
	DisplayBelowAverage(playerNameAr,scoreAr, numPlayers,averageScore);

return 0;

}

//inputDataFunctionCode
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef)
{//While the number of players is less than the length of the array
	while (numPlayersRef < array_size)	
	{//Prompt for the player's name
		cout << "Enter Player Name (Q to Quit) : " << endl;
		cin >> playerNameAr[numPlayersRef];

		//If the user entered Q, break out of the loop
		if ((playerNameAr[numPlayersRef] == "Q") || (playerNameAr[numPlayersRef] == "q"))
		{break;}

		//Prompt the user for the player's score
		cout << "Enter Score For : " << endl;
		cin >> scoreAr[numPlayersRef];
		cin.ignore(50, '\n');
		numPlayersRef++;}}




//displayPlayerData function Code
void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers)
{
	cout << setw(10) << left << "\n  Name" << setw(5) << right << "Score" << endl;

	for(int i = 0; i < numPlayers; i++)
        cout << setw(10) << left << playerNameAr[i] << setw(5) << right << scoreAr[i] << endl;
}

//calculateAverageScore function Code
double CalculateAverageScore(const int scoreAr[], int numPlayers)
{
    int i;
    double averageScore, totalScore;
    for(i = 0, totalScore = 0; i < numPlayers; i++)
         totalScore += scoreAr[i];
    averageScore = totalScore / numPlayers;
    cout << "\nAverage Score: " << averageScore << endl << endl;
    return averageScore;
}


//displayBelowAverage Function Code

void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double 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)
            cout << setw(10) << left << playerNameAr[i] << setw(5) << right << scoreAr[i] << endl;
}

Open in new window

hcaburksAsked:
Who is Participating?
 
Surendra NathTechnology LeadCommented:
the average score is not passed back to the main function, although it is caliculated in the caliculate averge score function....

//Call the CalculateAverageScore function and assign the returned value in average score
CalculateAverageScore(scoreAr, numPlayers);


should be written like below

//Call the CalculateAverageScore function and assign the returned value in average score
averageScore = CalculateAverageScore(scoreAr, numPlayers);
0
 
käµfm³d 👽Commented:
Side comment:  I realize you are learning to code, so take this as advice, not criticism. When you comment your code, comment why you are doing something, not what you are doing. Unless you are writing complete garbage (which most of us have done in the beginnings of our careers), it is easy for another programmer to read the code and see what you are doing. What's more difficult to grasp is why a programmer did something the way that he did.
0
 
Surendra NathTechnology LeadCommented:
what is the output that you are getting currently
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
hcaburksAuthor Commented:
Here is my current output. It should have Bob Sue and Pat and there scores in the Below average section. Instead it returns nothing.
lab5AOutput.docx
0
 
arober11Commented:
Hi

To start with you only have one true constant array_size, the rest are variables, so a slightly misleading comment. The two arrays could be left where they are but I'd personally stick them along with a definite variable averageScore in the main function.  As to the reason why your getting nothing out, it's down to you not doing anything with the results from your CalculateAverageScore() call, nothing a averageScore =  can't solve.

Try:

// constants
const int array_size=100;

//main Body code
int main() {

        string playerNameAr[array_size];
        int numPlayers = 0;
        int scoreAr[array_size];
        double averageScore;

        cout << fixed << showpoint << setprecision(2);
        //Call the inputData function
        InputData(playerNameAr,scoreAr, numPlayers);

        //Call the DisplayPlayerData function
        DisplayPlayerData(playerNameAr,scoreAr, numPlayers);

        //Call the CalculateAverageScore function and assign the returned value in average score
        averageScore = CalculateAverageScore(scoreAr, numPlayers);

        //Call the DisplayBelowAverage function
        DisplayBelowAverage(playerNameAr,scoreAr, numPlayers,averageScore);

return 0;

}

Open in new window

0
 
hcaburksAuthor Commented:
Thank you for that. I figured it was something easy I was just missing.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.