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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
//--------------------------------------------------------------------------------
//Programming Assignment: LAB4
//Developer: Sierra McGivney
//Date Written: 04/02/2014 - 04/04/2014
//Purpose: Video Game Player Program
//--------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//functions
int inputData(string name[], double score[], int x, int &count, int &highest, double &scoreTot);
void displayData(string name[], double score[], int x, int &count, double &scoreTot, int &highest);
//main function
void main()
{
string name[100]; //Array for name entries
double score[100] = { 0 }; //Array for the scores
double scrAvg = 0.0; //score average
int x = 0;
int highest = 0; //use this to dictate where to stop in the following function
int count = 0; //total number of players
double scoreTot = 0.0;
//call functions
inputData(name, score, x, count, highest, scoreTot); //input
if (count != 0)
{
displayData(name, score, x, count, scoreTot, highest); //ouput function
}//end if loop
return;
}//end main function
//Input and Display name and score
int inputData(string name[], double score[], int x, int &count, int &highest, double &scoreTot)
{
//loop
for (int x = 0; x <= 99; x++)
{
cin.sync(); //If I don't include this, my loop will not allow me to enter a new name, and skips right to score.
cout << "Player name (Q to quit): "; //name
getline(cin, name[x]);
//Quit Options
if ((name[x] == "Q") || (name[x] == "q"))
{
highest = count;
return count; //Exit the function
}
else
{
count = count + 1;
cout << "Player Score: "; //score
cin >> score[x];
while ((score[x] < 0.0) || (score[x] > 9999))
{
//enter score
cout << "Error: Score must be between 0 and 9999, in numeric form." << endl;
cout << "Enter score: ";
cin >> score[x];
cout << "\n";
}//end while loop
scoreTot = scoreTot + score[x];
cout << "\n";
}//end else if
}//end for loop
}//end function
void displayData(string name[], double score[], int x, int &count, double &scoreTot, int &highest)
{
//declarations
double scrAvg = 0.0;
cout << setw(8) << "\n\tName\t\tScore" << endl;
for (x = 0; x <= highest; x++)
{
//Display Output
if ((name[x] == "Q") || (name[x] == "q"))
{
break;
}
else
{
cout << setw(8) << "\t" << name[x] << "\t\t" << score[x] << endl;
}
}//end for loop
scrAvg = scoreTot / count; //calc Avg
//display avg
cout << "\nThe score average was: " << scrAvg << endl;
//below avg
cout << "\nPlayers who scored below average:" << endl;
cout << setw(8) << "\n\tName\t\tScore" << endl;
for (x = 0; x <= highest; x++)
{
//Display Output
if (score[x] <= scrAvg)
{
cout << setw(8) << "\t" << name[x] << "\t\t" << score[x] << endl;
}
else
{
break;
}//end else if
}//end for loop
}//end function
|