Review my Problem

Feb 15, 2013 at 5:20pm
Can anyone explain what could be better about this code please?
Is the use of if, else if, while statements being used correctly?


********************************************************************************

#include <iostream>
using namespace std;

int main()

{
int score;
char choice;
do{

cout<<" *** Grading! ***"<<endl;
cout<<" Please enter score: ";
cin>>score;
if (score==100){
cout<<" You scored a perfect score! good job. ("<<score<<")";
}
if (score>=90 && score<=99){
cout<<" You got an A! ("<<score<<"%)";
}
else if (score>=80 && score<=89){
cout<<" You got a B! ("<<score<<"%)";
}
else if (score>=70 && score<=79){
cout<<" You got a C! ("<<score<<"%)";
}
else if (score>100){
cout<<" Invalid input, try again";
}
else {
cout<<" Sorry, you failed. ("<<score<<"%)";
}
cout<<" Continue grading? (Y/N)";
cin>>choice;
}while (choice=='y' || choice=='Y');


cin.get();
return 0;

}


********************************************************************************
Last edited on Feb 15, 2013 at 5:24pm
Feb 15, 2013 at 5:54pm
I think it's quite fine. Just add else before 2nd if, though this program would be working fine as well, but after adding else it'll become efficient. As no condition is checked after else's if one becomes true.
Topic archived. No new replies allowed.