Need Help.

I have been stuck on this the whole weekend. I was finally able to get the max and min numbers, now I need to compare the averages and display the highest one as the winner.
The user is to enter a name, followed by five judge scores and those scores are then sent to validation via function. After validation, the scores are sent to the average function, in which, the highest and lowest number is called, then executes the average. I am stuck on how the program is to run through the averages and distinguish which is the winner.... Any suggestions will help and critique on my code on what could make it better would be awesome, as well. Thanks again gents!

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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

double Score_Validation(double score);
double Calc_Average(double score1, double score2, double score3, double score4, double score5);
double Find_Highest(double score1, double score2, double score3, double score4, double score5);
double Find_Lowest(double score1, double score2, double score3, double score4, double score5);

int main()
{
	double score1, score2, score3, score4, score5, score, average;
	string starName, winnerName;
	
	cout << "Enter the stars name, or enter done if no more stars: " << endl;
	getline(cin, starName);
	
	
	for (int count = 0; starName != "done"; count++)
	{	

		cout << "Enter judge 1 score: ";
		cin >> score;
		score1 = Score_Validation(score);
		
		cout << "Enter judge 2 score: ";
		cin >> score;
		score2 = Score_Validation(score);
		
		cout << "Enter judge 3 score: ";
		cin >> score;
		score3 = Score_Validation(score);
		
		cout << "Enter judge 4 score: ";
		cin >> score;
		score4 = Score_Validation(score);
		
		cout << "Enter judge 5 score: ";
		cin >> score;
		score5 = Score_Validation(score);

		cout << "Enter the stars name, or enter done if no more stars: " << endl;
		cin.ignore();
		getline(cin, starName);

		
	}
	
	average = Calc_Average(score1, score2, score3, score4, score5);

	//determines the winner

		

	 
	// cout << "... and the winner is " << starName << " with a score of " << setprecision(2) << fixed << average;

	cout << endl << endl;
	system("pause");
	return(0);
}
double Score_Validation(double score)
{
	while (score < 1 || score > 10)
	{
		cout << "Invalid score entered, please enter scores between 1 and 10";
		cout << "\nEnter correct score: ";
		cin >> score;
	}
	return(score);
}
double Calc_Average(double score1, double score2, double score3, double score4, double score5)
{
	double average, totalScore, highest, lowest, divideBy3 = 3;

	highest = Find_Highest(score1, score2, score3, score4, score5);
	lowest = Find_Lowest(score1, score2, score3, score4, score5);

	totalScore = score1 + score2 + score3 + score4 + score5;


	average = (totalScore - highest - lowest) / divideBy3;
	cout << "\nThe average is " << setprecision(2) << fixed << average;

	return(average);
}

double Find_Highest(double score1, double score2, double score3, double score4, double score5)
	{
		double highest = 1;
		
		if (score1 > highest)
			highest = score1;
		if (score2 > highest)
			highest = score2;
		if (score3 > highest)
			highest = score3;
		if (score4 > highest)
			highest = score4;
		if (score5 > highest)
			highest = score5;

		cout << " and the highest is " << highest << endl;

		return(highest);
	}
double Find_Lowest(double score1, double score2, double score3, double score4, double score5)
{
	double lowest = 10;

	if (score1 < lowest)
		lowest = score1;
	if (score2 < lowest)
		lowest = score2;
	if (score3 < lowest)
		lowest = score3;
	if (score4 < lowest)
		lowest = score4;
	if (score5 < lowest)
		lowest = score5;

	cout << " the lowest is " << lowest << endl;

	return(lowest);
}
  
Last edited on
Please try to use code tags around code.
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
closed account (48T7M4Gy)
If there are 5 scores and you have calculated the average of them (there is only one average) along with the maximum and minimum scores of that group then the winner is easily determined. So much so that you don't even need to know the minimum or the average.

Can I suggest, since you ask, and we have seen this request many times before over the previous few months, you read your code.
Last edited on
After reviewing the code and a little research, maybe I am misunderstanding how a "while loop" works. I am still stuck with the same code as above. I entered three names, each with 5 different scores and when the winner comes out.. The winner comes out to be name "done" which is my sentinal value to end the loop!!! The only other thing I can think of is adding another loop in the Calc_Average function, and I have tried that and the program went crazy. Just need a little guidance, as I am new to programming and not the answer to the problem.
Last edited on
closed account (48T7M4Gy)
Try here:
http://www.cplusplus.com/forum/general/178831/
Topic archived. No new replies allowed.