I have been reading a book on C++ for a few days and just put this code together to play with if/else commands. There are a few errors, as follows.
line 35 error: expected '}' before 'else'
line 38 error: expected '}' before 'else'
line 41 error: expected unqualified-id before 'else'
line 43 error: expected declaration before '}' token
I apologize for not having comments in there. If needed I can post some. I'm using code blocks 10.05. I also wanted to ask about the if statement on line 15. Is all that legal?
line 35 error: expected '}' before 'else'
line 38 error: expected '}' before 'else'
line 41 error: expected unqualified-id before 'else'
line 43 error: expected declaration before '}' token
Rich (BB code):
1 #include <iostream>
2
3 using namespace std;
4 typedef unsigned short int ushort;
5
6 int main()
7 {
8 ushort a;
9 ushort b;
10 cout << "Enter a whole number less than ten: ";
11 cin >> a;
12
13 if (a < 10)
14 {
15 if (a > 0)
16 cout << "Enter a whole number less than ten: ";
17 cin >> b;
18 ushort c = a + b;
19 {
20 if (b < 10)
21 {
22 if (b > 0)
23 cout << "the sum = " << c << "\n";
24 {
25 if (c <=18)
26 {
27 if (c >=2)
28 cout << "Correct!";
29 else
30 cout << "Incorrect!";
31 }
32 else
33 cout << "Incorrect!";
34 }
35 else
36 cout << "Error!";
37 }
38 else
39 cout << "Error!";
40 }
41 else
42 cout << "Error!";
43 }
44 else
45 cout << "Error!";
46
47 cin.get();
48 return 0;
49}
Last edited: