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
|
// Cassandra Hamric
// Sinclair's Got Talent
// This program is not finished
//This program will find the winner of a talent contest by dropping contestants highest and lowest score and dividing by the leftover scores (3).
// In the event of a tie, winner will be first performer.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Function Prototypes
double ValidScore (double); // Ensures Scores are not lower than 1 or greater than 10.
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);
double calcAvgScore(double, double, double, double, double);
int main()
{
// variables for user input
bool isValid;
double score1, score2, score3, score4, score5, score;
int highest, lowest;
double winnerAverage;
string name, winnerName;
//Get Contestants names, when Done is entered loop quits
do
{
cout <<"Enter the name of the star, enter Done when there are no more stars.";
cin >> name;
cout << endl;
if (name != "Done")
{
cout <<"Enter Judge 1's Score: ";
cin >> score;
score1 = ValidScore (score);
cout <<"Enter Judge 2's Score: ";
cin >> score;
score2 = ValidScore (score);
cout <<"Enter Judge 3's Score: ";
cin >> score;
score3 = ValidScore (score);
cout <<"Enter Judge 4's Score: ";
cin >> score;
score4 = ValidScore (score);
cout <<"Enter Judge 5's Score: ";
cin >> score;
score5 = ValidScore (score);
}
double average = calcAvgScore (score1, score2,score3,score4,score5);
if (average > winnerAverage)
{
winnerAverage = average;
winnerName = name;
}
} while (name != "Done");
// Calculating Averages (drops highest and lowest achieved score, then divides by remaining scores (3))
double calcAvgScore(double score1, double score2, double score3, double score4, double score5) // HERE IS WHERE A ; IS EXPECTED and LOCAL FUNCTION DEFINITIONS ARE ILLEGAL
{
double highest = findHighest(score1, score2, score3, score4, score5);
double lowest = findLowest(score1, score2, score3, score4, score5);
double total = (score1 + score2 + score3 + score4 + score5 - highest - lowest);
double average = (total) / 3;
return average;
}
// Declaring Winner
cout << " ... and the winner is " <<winnerName <<" with a score of " <<winnerAverage <<endl;
system ("pause");
return 0;
}
// Validate Score is not less than 1 or greater than 10
double ValidScore (int score)
{
while ( score < 1 || score > 10)
{
cout <<" Please enter a score between 1-10: ";
cin >> score;
}
return score;
}
// define function to find lowest score for each contestant
double findLowest(double score1, double score2, double score3, double score4, double score5)
{
double lowest = score1;
if (score2 < lowest)
lowest = score2;
if (score3 < lowest)
lowest = score3;
if (score4 < lowest)
lowest = score4;
if (score5 < lowest)
lowest = score5;
return lowest;
}
// define function to find highest score for each contestant
double findHighest(double score1, double score2, double score3, double score4, double score5)
{
double highest = score1;
if (score2 > highest)
highest = score2;
if (score3 > highest)
highest = score3;
if (score4 > highest)
highest = score4;
if (score5 > highest)
highest = score5;
return highest;
}
|