+ 1
what's the problem with this code?
#include <iostream> using namespace std; int main(); { int mark; cout << "Enter your marks"; cin >> mark; if (mark >= 50) { cout << "You passed." << endl; if (mark >= 70) {cout << "Distinction"}; if (mark >= 60) {cout << "First class"}; if (mark == 100) { cout <<"Perfect!" << endl; } } else { cout << "You failed. :()" << endl; } return 0; }
3 Answers
+ 2
Mitesh you should use else if
if (marks>=50)
{
cout<<"you passed"<<endl;
if(marks==100)
cout<<"perfect"<<endl;
else if(marks>=70)
cout<<"distinction"<<endl;
else
cout<<"first class"<<endl;
}
the error in your program is that when you will enter 100 it will give output as
distinction
first-class
perfect
0
You have extra semicolons
{cout << "Distinction"};
{cout << " First clasd"};
Make it like this:
{cout << "Distinction"; }
{cout << " First class"; }
and it shoult compile.
0
dont use if for every condition use else for new condition