+ 1

What's wrong with this program?

I get the output. But below the output something is error in that. I don't know what's that? Pls explain. #include <iostream> using namespace std; int main() { int marks=100; cout <<"enter the marks:"<<endl; cin>>marks; if(marks>=60) cout<<"grade A"<<endl; else if(marks>=30&&marks<60) cout<<"grade B"<<endl; else if(marks>=20&&marks<30) cout <<"grade C"<<endl; else cout<<"fail"<<endl; return 0; }

12th Jan 2021, 10:51 AM
Jawahirullah
Jawahirullah - avatar
1 Odpowiedź
+ 4
else cout << "fail" << endl; return 0; The problem is the compiler recognise "return 0" as part of the else statement so you have to unindent it since you don't use curly brackets. Remember that without curly brackets, multiple statements are not allowed.
12th Jan 2021, 10:54 AM
noteve
noteve - avatar