+ 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; }
3 Answers
+ 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.