illegal else without matching if , would love if my mistake is explained

would love if my mistake is explained
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream.h>
void main ( ) {
	int x;
	cin>>x;
	if(x>50){
		cout<<"pass";
	int y=x/10;
		switch(y){
		case 10:
			cout<<"A";
		case 9:
			cout<<"A";
		case 8:
			cout<<"B";
		case 7:
			cout<<"C";
		case 6:
			cout<<"D";
		case 5:
			cout<<"E";}
	else 
		cout <<"fail";}}
You forgot the closing } to the if. Line 2 should be:

cout<<"E";}}

Main must return an int: int main() { //...
There is no iostream.h header: #include <iostream>

Anyway, if you aligned your code better it would be easier to spot this error:

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
#include <iostream>
int main ( ) {
	int x;
	cin>>x;
	if(x>50) {
		cout<<"pass";
		int y=x/10;
		switch(y) {
			case 10:
				cout<<"A";
			case 9:
				cout<<"A";
			case 8:
				cout<<"B";
			case 7:
				cout<<"C";
			case 6:
				cout<<"D";
			case 5:
				cout<<"E";
		}
	else 
		cout <<"fail";
	}
}
thank you very much ispil , i just started learning this language and i thought the } ends after else , appreciate it alot
Topic archived. No new replies allowed.