Im having an issue with a class project

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

using namespace std;

int main ()
{
string diverName = " ", diverCity = " ";
int highestScore = 0, lowestScore = 20, score = 0, count = 0, judge = 1;
double degDif, overallScore = 0, averageScore = 0, overallAverage = 0, totalScore = 0;
char continueLoop = 'y';

cout << "   Report to the media" << endl;
cout << "Event: diving competition" << endl;

do
{
	
	cout << "Enter the divers name:";
	getline(cin, diverName);
	cout << "Enter the divers city:";
	getline(cin, diverCity);
do
{
	cout << "Enter score given by judge #" << judge << ":";
	cin >> score;
	judge++;
	
	if (score < 0 || score > 10)
	cout << "Invalid score - Please reenter (valid range: 0 - 10" << endl;
	judge--;
	cout << "Enter score given by judge #" << judge <<":";
	cin >> score;
	totalScore += score;
if (score > highestScore)
	highestScore = score;
if (score < lowestScore)
	lowestScore = score;
	totalScore -= highestScore;
	totalScore -= lowestScore;
	averageScore = totalScore/3;
	cout << setprecision (2) << fixed;
}
while (judge < 5);

	cout << "what was the degree of difficulty?";
	cin >> degDif;
while (degDif < 1.00 || degDif > 1.67)
{	cout << "Invalid degree of difficulty - Please reenter (valid range: 1 - 1.67)";
	cin >> degDif;
	overallScore = averageScore*degDif;
	cout << "Diver: " << diverName << ". city: " << diverCity;
	cout << "Overall Score was " << overallScore;
	overallAverage += overallScore/count;
	cin.ignore();
	count++;
	cout << "Do you want to process another diver (y/n)?";
	cin >> continueLoop;
}

}
while (continueLoop == 'y' || continueLoop == 'Y');
cout << "       Event Summary";
cout << "Number of divers participating: " << count;
cout << "Average score of all divers: " << overallAverage;

return 0;
}


Here is my issue, i cant figure out why when i compile this program it goes all crazy on me after i put in 3 or 4 numbers for judges scores. This program is makeing me crazy :(
You don't add {} to your if statements. For example,
1
2
3
4
5
if (score < 0 || score > 10)
    cout << "Invalid score - Please reenter (valid range: 0 - 10" << endl;
    judge--;
    cout << "Enter score given by judge #" << judge <<":";
    cin >> score;
Here only the second line is inside the if. All others happen every time. You have judge++ and judge--, so judge will never reach 5. The right way is
1
2
3
4
5
6
if (score < 0 || score > 10){
    cout << "Invalid score - Please reenter (valid range: 0 - 10" << endl;
    judge--;
    cout << "Enter score given by judge #" << judge <<":";
    cin >> score;
}
The same is true for your other ifs.
Topic archived. No new replies allowed.