1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void inputData(string, double, int);
void displayPlayerData(string, double, int);
double calculateAvgScore(double, int);
void displayBelowAvg(double, string, double);
int main()
{
const int SIZE=100;
string playerName[SIZE];
double playerScore[SIZE], AverageScore=0;
inputData(playerName, playerScore, SIZE);
displayPlayerData(playerName, playerScore, SIZE);
AverageScore=calculateAvgScore(playerScore, SIZE);
displayBelowAvg(AverageScore, playerName, playerScore);
}
void inputData(string names[], double score[], int size)
{
//input player name and score
int counter=0;
while(counter<size)
{
cout<<"Enter player name or type 'Q' to quit: ";
cin>>names[counter];
if(names[counter]=="Q"||names[counter]=="q")
{
break;
}
cout<<"Enter score: ";
cin>>score[counter];
counter++;
}
}
void displayPlayerData(string names[], double score[], int size)
{
//display the name and score of each player
int counter=0;
while(counter<size)
{
cout<<"Name: "<<names[counter]<<endl;
cout<<"Score: "<<score[counter]<<endl;
}
}
double calculateAvgScore(double score[], int size)
{
//calculate avg score and return it by value
double totalScore, totalAverage;
int counter=0;
while(counter<size)
{
totalScore=totalScore+score[counter];
counter++;
}
totalAverage=totalScore/counter;
cout<<totalAverage;
return totalAverage;
}
void displayBelowAvg(double AvgScore, string names[], double score[])
{
//display name and score for any player scoring below average
int i=0;
while(i=0, i<100, i++)
{
if(score[i]<AvgScore)
{
cout<<names[i]<<endl;
cout<<score[i]<<endl;
}
}
}
|