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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// Video Game Player Program
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
// Prototypes
int inputData( string[], int[], int &) ;
void displayPlayerData( string[], int[], int&);
double calcAvgScore(int[], int&) ;
void displayBelowAvg(string[], int[], double&, int&, int&) ;
const int SIZE = 100;
int main()
{
// array of strings
string playerName[SIZE] ;
// array of ints
int score [SIZE] ;
int numPlayers = 0;
int scores =0;
double avgScore =0;
// call input data function
inputData(playerName, score,numPlayers);
// call display Player function
displayPlayerData(playerName, score,numPlayers);
// call calculate average score function
calcAvgScore(score, numPlayers);
// call display below average function
displayBelowAvg( playerName, score, avgScore,scores, numPlayers);
return 0;
system("pause") ;
}
int inputData( string playersName[], int scores[], int & numPlayers)
{
string playerName[SIZE];
int score[SIZE];
string toupper =" Q";
while(numPlayers < SIZE && playerName[numPlayers] != ("Q"))
{
playerName[numPlayers] = numPlayers * numPlayers;
cout << "Please enter player name:" << endl;
cin >> playerName[numPlayers];
if ( playerName[numPlayers] == "Q")
cout << " The Q was entered to quit!" << endl;
if (playerName[numPlayers] != "Q")
cout << "Please enter player score:" << endl;
cin.ignore();
numPlayers++;
for( int scores=0; scores < SIZE; scores ++)
{score[scores] = scores * scores;}
return numPlayers;
}
return 0;
}
void displayPlayerData( string playerName[], int score[], int& numPlayers)
{
for( numPlayers = 0; numPlayers < SIZE; numPlayers++);
cout << " The players are:" << playerName[numPlayers] << " ";
for (int scores = 0;scores < SIZE; scores ++)
cout << " The scores are:" << score[scores] << " ";
}
double calcAvgScore(int score[], int& numPlayers)
{
double total =0;
int scores=0;
double avgScore =0;
for (int scores =0; scores < SIZE; scores ++)
{ total += score[scores] ;}
avgScore= total / scores;
cout << " The average score is:" << avgScore << endl;
cout << setprecision(2) << fixed;
return avgScore;
}
void displayBelowAverage(string playerName[], int score[], double&avgScore, int&scores, int& numPlayers)
{
if(score[scores] < avgScore)
cout << " The players that are below average are:" << playerName[numPlayers] << score[scores] << endl;
}
|