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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
//Function prototypes
double getScore(double &, int &);
double calcAvgScore(double, double, double, double, double, double&);
double findLowest(double, double, double, double, double, double&);
double findHighest(double, double, double, double, double, double&);
int main()
{
string contestant;
ofstream inFile;
ifstream readFile;
char again;
double score1, score2, score3, score4, score5,
average, highest, lowest;
cout << "*************************************************************\n"
<< "*-----------------------------------------------------------*\n"
<< "* Sinclair's Got Talent *\n"
<< "*************************************************************\n";
inFile.open("scores.txt");
do
{
int i = 1;
cout << "Enter the name of the contestant: ";
cin >> contestant;
getScore(score1, i);
getScore(score2, i);
getScore(score3, i);
getScore(score4, i);
getScore(score5, i);
calcAvgScore(score1, score2, score3, score4, score5, average);
findLowest(score1, score2, score3, score4, score5, lowest);
findHighest(score1, score2, score3, score4, score5, highest);
cout << "\t Lowest score: " << lowest << endl;
cout << "\tHighest score: " << highest << endl;
inFile << contestant << ' ' << average << endl;
cout << "More contestants? 'Y' or 'N': ";
cin >> again;
} while (again == 'y' || again == 'Y');
inFile.close();
readFile.open("scores.txt");
string winnerTemp, winner;
double total, test = 1;
while (readFile >> winnerTemp >> total)
{
if (total > test)
{
test = total;
winner = winnerTemp;
}
}
cout << "\n";
cout << "************************************************************\n";
cout << "\t\tAnd the winner is: " << winner << endl;
cout << "************************************************************\n";
cout << "\n";
readFile.close();
return 0;
}
//Functions
double getScore(double &score, int &i)
{
cout << "Enter Judge #" << i << "'s score: ";
cin >> score;
if (score < 0 || score > 10)
{
cout << "Please enter a valid score (1-10). Try again: ";
cin >> score;
}
return i++;
}
double calcAvgScore(double score1, double score2, double score3,
double score4, double score5, double &average)
{
double totalScore;
totalScore = (score1 + score2 + score3 + score4 + score5);
average = totalScore / 5;
cout << "\tAverage score: " << average << endl;
return average;
}
double findLowest(double score1, double score2, double score3,
double score4, double score5, double &lowest)
{
lowest = score1;
if (score2 < lowest)
lowest = score2;
if (score3 < lowest)
lowest = score3;
if (score4 < lowest)
lowest = score4;
if (score5 < lowest)
lowest = score5;
return lowest;
}
double findHighest(double score1, double score2, double score3,
double score4, double score5, double &highest)
{
highest = score1;
if (score2 > highest)
highest = score2;
if (score3 > highest)
highest = score3;
if (score4 > highest)
highest = score4;
if (score5 > highest)
highest = score5;
return highest;
}
|