Expected unqualified-id

Hi, I'm having some issues with my code and I am getting some odd errors.

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

int main() {

cout << "Enter three numbers: " << endl;
char cond1,cond2,cond3;
int num1, num2, num3;
cin >> num1 >> num2 >> num3;

if (num1>num2);{
cond1 = 't';}
else{
cond1 = 'f'
}
if (num1>num3){
cond2 = 't'}
else{
cond2 = 'f'}
if (num2>num3){
cond3 = 't'}
else{
 cond3 = 'f'}


if (cond1 == 't' && cond2 == 't'){
cout << num1 << " is the maximum" << endl;
else if (cond1 == 't' && cond2 == 'f'){
cout << num3 << " is the maximum" << endl;}
else if (cond1 == 'f' && cond3 == 't'){
cout << num2 << " is the maximum" << endl;}
}

if (cond1 == 'f' && cond2 == 'f') {
cout << num1 << " is the minimum" << endl;
}
else if (cond1 == 't' && cond3 == 'f'){
cout << num2 << " is the minimum" << endl;}
else if (cond2 == 't' && cond3 == 't');{
cout << num3 << " is the minimum" << endl;}
}
return 0;


Please excuse the sloppy formatting.

Here are the errors I am receiving when I try to run the code:

1
2
3
4
5
6
7
8
9
Lab3P2.cpp: In function 'int main()':
Lab3P2.cpp:15: error: expected `}' before 'else'
Lab3P2.cpp: At global scope:
Lab3P2.cpp:15: error: expected unqualified-id before 'else'
Lab3P2.cpp:18: error: expected unqualified-id before 'if'
Lab3P2.cpp:20: error: expected unqualified-id before 'else'
Lab3P2.cpp:22: error: expected unqualified-id before 'if'
Lab3P2.cpp:24: error: expected unqualified-id before 'else'
Lab3P2.cpp:28: error: expected unqualified-id before 'if' 


I have no idea what they mean by "expected unqualified-id before", and every time I add the } before "else" in line 15, I just get more errors.

Any help would be greatly appreciated.
Last edited on
Remove the ; from line 13.
You have a semicolon on line 13 that shouldn't be there.

16, 19, 22, 25 all require semicolons (before the brace but after the letter):

cond2 = 't' ; /*<--*/ }
Thanks for the help so far. I did what you guys said, and now I've gotten these errors:

1
2
3
4
5
6
7
8
Lab3P2.cpp: In function 'int main()':
Lab3P2.cpp:29: error: expected `}' before 'else'
Lab3P2.cpp: At global scope:
Lab3P2.cpp:35: error: expected unqualified-id before 'if'
Lab3P2.cpp:38: error: expected unqualified-id before 'else'
Lab3P2.cpp:40: error: expected unqualified-id before 'else'
Lab3P2.cpp:40: error: expected unqualified-id before '{' token
Lab3P2.cpp:42: error: expected declaration before '}' token 


So I get a few more of the expected unqualified-id errors, but in different lines now, and I'm still not entirely sure what this is supposed to mean.

Here's the updated code, if it helps:

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

#include<iostream>
#include<cmath>
using namespace std;

int main() {

cout << "Enter three numbers: " << endl;
char cond1,cond2,cond3;
int num1, num2, num3;
cin >> num1 >> num2 >> num3;

if (num1>num2){
cond1 = 't';}
else{
cond1 = 'f';
}
if (num1>num3){
cond2 = 't';}
else{
cond2 = 'f';}
if (num2>num3){
cond3 = 't';}
else{
 cond3 = 'f';}


if (cond1 == 't' && cond2 == 't'){
cout << num1 << " is the maximum" << endl;
else if (cond1 == 't' && cond2 == 'f'){
cout << num3 << " is the maximum" << endl;}
else if (cond1 == 'f' && cond3 == 't'){
cout << num2 << " is the maximum" << endl;}
}

if (cond1 == 'f' && cond2 == 'f') {
cout << num1 << " is the minimum" << endl;
}
else if (cond1 == 't' && cond3 == 'f'){
cout << num2 << " is the minimum" << endl;}
else if (cond2 == 't' && cond3 == 't');{
cout << num3 << " is the minimum" << endl;}
}
return 0;
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
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<cmath>
using namespace std;

int main() {

cout << "Enter three numbers: " << endl;
char cond1,cond2,cond3;
int num1, num2, num3;
cin >> num1 >> num2 >> num3;

if (num1>num2){
cond1 = 't';
}
else{
cond1 = 'f';
}
if (num1>num3){
cond2 = 't';
}
else{
cond2 = 'f';
}
if (num2>num3){
cond3 = 't';
}
else{
 cond3 = 'f';
}


if (cond1 == 't' && cond2 == 't'){
cout << num1 << " is the maximum" << endl;
}
else if (cond1 == 't' && cond2 == 'f'){
cout << num3 << " is the maximum" << endl;
}
else if (cond1 == 'f' && cond3 == 't'){
cout << num2 << " is the maximum" << endl;
}

if (cond1 == 'f' && cond2 == 'f') {
cout << num1 << " is the minimum" << endl;
}
else if (cond1 == 't' && cond3 == 'f'){
cout << num2 << " is the minimum" << endl;
}
else if (cond2 == 't' && cond3 == 't');{
cout << num3 << " is the minimum" << endl;
}
return 0;
}


Missing '}' at the end and a few other edits done.
Last edited on
You really need to work on indenting your code:

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

int main()
{

	cout << "Enter three numbers: " << endl;
	char cond1,cond2,cond3;
	int num1, num2, num3;
	cin >> num1 >> num2 >> num3;

	if (num1>num2)
	{
		cond1 = 't';
	}
	else
	{
		cond1 = 'f';
	}
	if (num1>num3)
	{
		cond2 = 't';
	}
	else
	{
		cond2 = 'f';
	}
	if (num2>num3)
	{
		cond3 = 't';
	}
	else
	{
		cond3 = 'f';
	}


	if (cond1 == 't' && cond2 == 't')
	{
		cout << num1 << " is the maximum" << endl;
	}// you were missing this
	else if (cond1 == 't' && cond2 == 'f')
	{
		cout << num3 << " is the maximum" << endl;
	}
	else if (cond1 == 'f' && cond3 == 't')
	{
		cout << num2 << " is the maximum" << endl;
	}

	if (cond1 == 'f' && cond2 == 'f')
	{
		cout << num1 << " is the minimum" << endl;
	}
	else if (cond1 == 't' && cond3 == 'f')
	{
		cout << num2 << " is the minimum" << endl;
	}
	else if (cond2 == 't' && cond3 == 't') //; // this doesn't belong here
	{
		cout << num3 << " is the minimum" << endl;
	}
//} // this doesn't go here	
	return 0;
} // it goes here 
Thanks CaptainBlastXD, works with your edits. Greatly appreciate all the help guys.
Topic archived. No new replies allowed.