Getting a missing semicolon error on a loop?

I'd say I'm about to scream but I've already screamed several times.

I'm getting a syntax error for a missing semicolon before { on line 34. However... that's part of my do-while loop and if I put a semicolon there it completely disregards my sentinel and if I type "Done" it just continues on with the program. This is my first time trying to use a string as a sentinel and there's a good chance I'm completely screwing it up. Help?

This is a homework assignment that's only partially finished - so ignore the seemingly random functions and such. I'm trying to test it a piece at a time but I'm stumped with this sentinel.

Also, please ignore that it uses a system pause. I know this is horrible programming practice but for some reason this is how our instructor wants us to do it!


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
133
134
135


#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Function prototypes

double validScore(int);   // Validates judges' score entries.
double findHighest(double,double,double,double,double); // Find highest score of each competitor
double findLowest(double,double,double,double,double); // Find lowest score of each competitor

int main()
{
bool isValid;
double score1, score2, score3, score4, score5;
int highest, lowest;

double score, winnerScore;
string name, winnerName;


cout << "Welcome to Sinclair's Got Talent!\n";

// Retrieve names, terminate loop when no more names
do 
{
cout << "Please enter the contestant's first name: " ;
cin >> name;
cout << endl;
}

while (name != "Done");
{
// Get 5 judges scores for each name

cout << "Enter judge 1 score: " ;
cin >> score;
score1 = validScore(score);


cout << "Enter judge 2 score: " ;
cin >> score;
score2 = validScore(score);

cout << "Enter judge 3 score: " ;
cin >> score;
score3 = validScore(score);

cout << "Enter judge 4 score: " ;
cin >> score;
score4 = validScore(score);

cout << "Enter judge 5 score: " ;
cin >> score;
score5 = validScore(score);
// Verification of input

cout << "Score 1 " << score1 << endl;
cout << "Score 2 " << score2 << endl;
cout << "Score 3 " << score3 << endl;
cout << "Score 4 " << score4 << endl;
cout << "Score 5 " << score5 << endl;
}
// Call average score calculation function






// Display name and score of winner.
cout << "The winner of the competition is " << winnerName << endl;
cout << "with a score of " << winnerScore << "!" << endl;



system("pause");
return 0;
}

// **********************************************************************
// *  Definition of function inputValidation. Checks judge score input  *
// *  to verify it is in between 1 and 10 and displays an error message *
// *  if it is not.                                                     *
// **********************************************************************

double validScore(int score)
{
	while (score<1 || score>10)
{
	cout << "Please enter a valid score between 1 and 10: " ;
	cin >> score;
}
return score;
}

	

int findHighest(int score1, int score2, int score3, int score4, int score5)
{
	int highest=1;
if (score1>highest)
	highest=score1;
else if (score2>highest)
	highest=score2;
else if (score3>highest)
	highest=score3;
else if (score4>highest)
	highest=score4;
else if (score5>highest)
	highest=score5;

return highest;
}

int findLowest(int score1, int score2, int score3, int score4, int score5)
{ 
	int lowest=10;
if (score1<lowest)
	lowest=score1;
else if (score2<lowest)
	lowest=score2;
else if (score3<lowest)
	lowest=score3;
else if (score4<lowest)
	lowest=score4;
else if (score5<lowest)
	lowest=score5;

return lowest;
}

Last edited on
Thats not quite how the do-while loop works.

It looks like this

1
2
3
4
5
do
{
     //Do all the stuffzies

}while(something);


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
Think you want this - 

do
{
	cout << "Please enter the contestant's first name: ";
	cin >> name;
	cout << endl;

	cout << "Enter judge 1 score: ";
	cin >> score;
	score1 = validScore(score);


	cout << "Enter judge 2 score: ";
	cin >> score;
	score2 = validScore(score);

	cout << "Enter judge 3 score: ";
	cin >> score;
	score3 = validScore(score);

	cout << "Enter judge 4 score: ";
	cin >> score;
	score4 = validScore(score);

	cout << "Enter judge 5 score: ";
	cin >> score;
	score5 = validScore(score);
	// Verification of input

	cout << "Score 1 " << score1 << endl;
	cout << "Score 2 " << score2 << endl;
	cout << "Score 3 " << score3 << endl;
	cout << "Score 4 " << score4 << endl;
	cout << "Score 5 " << score5 << endl;

} while (name != "Done");
Last edited on
@TarikNeaj

But that would require him to input scores even though he's "done". Perhaps it should be a while loop with a break statement
1
2
3
4
5
6
7
8
9
10
while (true)
{
    //prompt for name
    //input name
    if (name == "Done")
        break;
    //prompt for scores
    //input scores
    //output scores
}
Yeh you're right @fg109. But it can be solved with a simle if statement

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
do
{
	cout << "Please enter the contestant's first name: ";
	cin >> name;
	cout << endl;

    if(name != "Done")
    {
	cout << "Enter judge 1 score: ";
	cin >> score;
	score1 = validScore(score);


	cout << "Enter judge 2 score: ";
	cin >> score;
	score2 = validScore(score);

	cout << "Enter judge 3 score: ";
	cin >> score;
	score3 = validScore(score);

	cout << "Enter judge 4 score: ";
	cin >> score;
	score4 = validScore(score);

	cout << "Enter judge 5 score: ";
	cin >> score;
	score5 = validScore(score);
	// Verification of input

	cout << "Score 1 " << score1 << endl;
	cout << "Score 2 " << score2 << endl;
	cout << "Score 3 " << score3 << endl;
 	cout << "Score 4 " << score4 << endl;
	cout << "Score 5 " << score5 << endl;
     }
} while (name != "Done");


I dont like having "true" as a condition, prefer a boolean, even though it works the same way.
Using that layout, I get an error that a string command cannot be used as a conditional operator.
Whoops, my bad! I typed = instead of == ... when I fixed that, it seems to have worked.
Yes!! Thank you fg109. My program now breaks correctly and doesn't ask for an additional input. Thank you again!! Now I can stop screaming at this assignment. :)
Topic archived. No new replies allowed.