Function and loop assistance

Hello everyone,
I am a first year programming student and I seem to be having a problem executing this C++ program.

The instructions are as follows:

During a skating competition, each performer will skate for 90 seconds showcasing their routine, and the performer will be evaluated by a 4-member panel of judges. The performer will be awarded a score between 0.0 and 10.0 by each of the judges. (The number of performers is not known, so Im assuming I need to use a do while loop as well)

To ensure fairness, his / her final score will be determined as follow:
• Highest score
• Lowest score
• Remaining two scores (each score will be counted twice.) See example on the next paragraph.

His / her average score will then be determined by tally up her total points from the judges and divided by 6. Here is an example:
• Ann performed her routine and she received the scores of 7.0, 8.0, 9.0, and 10.0 from the judges.
• Her running total would be: 7.0 + (8.0 x 2) + (9.0 x 2) + 10.0 = 51.0 (points)
• Her average score will be: 51.0 / 6 = 8.5
• You should notice that I am using these easy-to-follow numbers in this example. They could have been 7.3, 8.1, 9.3, 9.9, etc.


Here is my code so far, and all functions that are included are mandatory. I've included notes where I really need help. Let me know if you need more details. Thanks guys
Sara

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
#include <iostream>
#include <string>
using namespace std;

//Function prototypes
void record_scores();
float calculate_average_score(float, float, float, float);
float get_lowest_score(float, float, float, float);
float get_higest_score(float, float, float, float);
float remainingScores(float, float, float, float);
void show_event_highlight();

float min, max, average;

int main()
{
	//Variables
	float score1, score2, score3, score4, average;
	

		//Display info to get performers name and scores
		record_scores();

		cin >> score1 >> score2 >> score3 >> score4; //Program will not continue past this point

		while (score1 < 0 && score1 > 10
			&& score2 < 0 && score2 > 10
			&& score3 < 0 && score3 > 10
			&& score4 < 0 && score4 > 10)
		{
			cout << "Please enter a valid score between 1 and 10";
		}

	
		//Calculate average score
		average = calculate_average_score(score1, score2, score3, score4);

		//Show details
		void show_event_highlight();
	

	
		
}

//Get performers name and scores received by judges
void record_scores()
{
	string name;

	cout << "Please enter performers name: ";
	getline(cin, name);
	cout << " Please enter " << name << " scores, separated by a space: " << endl;
	
}

float calculate_average_score(float score_1, float score_2, float score_3, float score_4)
{
	float average, leftover;
	
	//Get lowest score
	min = get_lowest_score(score_1, score_2, score_3, score_4);
	//Get highest score
	max = get_higest_score(score_1, score_2, score_3, score_4);
	leftover = remainingScores(score_1, score_2, score_3, score_4); //How do I find the two remaining scores?
	average = (min + max + score + score...) / 6; //This is where I am really confused. When I am able to retrieve the remaining scores, how do I implement them into my program?
return average;


}

float get_lowest_score(float entry1, float entry2, float entry3, float entry4)
{
	min = entry1;
	if (entry2 < entry1)
		min = entry2;
	if (entry3 < entry2)
		min = entry3;
	if (entry4 < entry3)
		min = entry4;
	return min;
}

float get_higest_score(float scoreOne, float scoreTwo, float scoreThree, float scoreFour)
{
	
	max = scoreOne;
	if (scoreTwo > scoreOne)
		max = scoreTwo;
	if (scoreThree > scoreTwo)
		max = scoreThree;
	if (scoreFour > scoreThree)
		max = scoreFour;
	return max;
}

float remainingScores(float num1, float num2, float num3, float num4)//Not sure if this is correct
{

	if (num1 != min && num1 != max)
		return num1 * 2;
	if (num2 != min && num2 != max)
		return num2 * 2;
	if (num3 != min && num3 != max)
		return num3 * 2;
	if (num4 != min && num4 != max)
		return num4 * 2;

}




void show_event_highlight()

{
	cout << "The average score amongst the performer was: " << average << endl;
}
(1) You should try to do all function calls from main.

(2) What is even the point of returning min and max and average if they are global variables? You can access these variables from any function.

(3) Take a look at your while condition:
1
2
3
4
while (score1 < 0 && score1 > 10
			&& score2 < 0 && score2 > 10
			&& score3 < 0 && score3 > 10
			&& score4 < 0 && score4 > 10)


How is it possible for a score to be less than 0 AND greater than 10, simultaneously? What should the && operator be replaced with?

(4) After printing out the message in line 31, you never give the user a chance to re-enter the scores. You should have another cin for the 4 scores afterwards (within the loop).

(5) Line 39: void show_event_highlight();

Thats not how you call a function. You've made a prototype here. Remove the word "void".
Last edited on
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
#include <iostream>
#include <string>

using namespace std;

int main() {
	string Athelete;
	
	cout << "\n\tName: ";
	getline ( cin, Athelete );
	
	if ( !Athelete.empty () ) {
		double Min = 10, Max = 0, Value, Total = 0;
		int Cnt = 0;
		
		do {
			cin >> Value;
			
			if ( Value > 0 && Value <= 10 ) {
				if ( Value < Min )
					Min = Value;
				if ( Value > Max )
					Max = Value;
				
				if ( Cnt == 1 || Cnt == 2)
					Value *= 2;
				
				Total += Value;
			}
			
		} while ( ++Cnt < 4 );
		
		cout << Athelete << "\n\t Total= " << Total 
			 << " Average = " << Total / 6 << endl;
		cout << "\t\t Max = " << Max << " Min = " << Min << endl;
	}
	else
		cout << "\n\nAborted!" << endl;
	
	return 0;
}
As for how to find the remaining two numbers, the if-statements are not needed (and they wouldn't work anyway).

The problem does not state you must print out the remaining two scores. It simply says you must calculate the average, using the running total. To find the running total, you dont need to know the remaining two scores, all you need is a general equation. You'll need to think about how the scores are added, and figure out a relatively simple equation that gives you the total. Then simply divide that by 6 and you'll have your average.


EDIT: If the remainingScores function is necessary, we can tweek the if-statements a little. Make a local variable within the function to hold one of the two remaining scores. After each if-condition (your if-conditions are kept the same), assign the number to the variable.

At the end of the function, return the variable.

so, pseudo-code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

if(condition)
remainingScore1 = num1;

if(condition)
remainingScore1 = num2;

..
..
..

return remainingScore1;

]



After this, getting the second of the two remaining scores should be easy as now you know 3 out of the 4 scores.

Last edited on
@shiftleft:

Firstly, We dont write code for people, we simply help them.
Secondly, you didn't stick to her requirements. The functions she listed are mandatory according to OP.
Last edited on
Topic archived. No new replies allowed.