+ 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; }

20th Sep 2016, 7:37 AM
Mitesh Vasava
Mitesh Vasava - avatar
3 ответов
+ 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
20th Sep 2016, 8:36 AM
Descifrador
Descifrador - avatar
0
You have extra semicolons {cout << "Distinction"}; {cout << " First clasd"}; Make it like this: {cout << "Distinction"; } {cout << " First class"; } and it shoult compile.
31st Oct 2016, 6:57 AM
Mladen Stupar
Mladen Stupar - avatar
0
dont use if for every condition use else for new condition
10th Jan 2017, 6:32 PM
Prateek Yadav
Prateek Yadav - avatar