#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Function prototypes declared before main function
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);
// declaring variables
string playerNameAr[100];
double scoreAr[100];
int numPlayers = 0;
double averageScore;
const int arraySize = 100;
void main()
{
const string playerNameAr[100];
const double scoreAr[100];
int numPlayers = 0;
double averageScore;
InputData(playerNameAr, scoreAr, numPlayers);
DisplayPlayerData(playerNameAr, scoreAr, numPlayers);
averageScore = CalculateAverageScore(scoreAr, numPlayers);
DisplayBelowAverage(playerNameAr, scoreAr, numPlayers, averageScore);
}
// function definitions go here
// InputData Function
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef)
{
int numPlayers = 0;
const int arraySize = 100;
while (numPlayersRef < arraySize)
{
cout << "Enter Player Name (Q to quit): " << endl;
getline(cin, playerNameAr[numPlayersRef]);
if (playerNameAr[&numPlayerRef] == "Q")
break;
cout << "Enter score for " << playerNameAr[numPlayersRef] << ": ";
cin >> scoreAr[numPlayersRef];
numPlayersRef++;
}
}
void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers)
{
int i = 0;
numPlayers = 0;
for(i < numPlayers)
{
cout << playerNameAr[i] << scoreAr[i] << endl;
i++;
}
}
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 << "Average Score: " << averageScore << endl << endl;
return averageScore;
}
void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double averageScore)
{
cout << "Players who scored below average ";
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;
}
}
kimmyfufu 0 Newbie Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.