#include <iostream>
usingnamespace 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<<"%)";
}
elseif (score>=80 && score<=89){
cout<<" You got a B! ("<<score<<"%)";
}
elseif (score>=70 && score<=79){
cout<<" You got a C! ("<<score<<"%)";
}
elseif (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;
}
so it all seems to work fine except that whenever i try to type in a 100% test score it activates both the 100% if and the else (sorry you failed). not too sure why. i fixed this my self by just making my else an else if and making it make sure that (score>=0 && score<=69) would activate properly but i still would like to know why the else command is acting so shaky?
What do you mean by that?
I think you don't understand why it didn't work. You had the initial if, and then you were missing an else, which meant you had started a whole new condition chain. Since 100 didn't satisfy the second condition chain, it was caught by the else clause.
ooohh
i see what you mean so it works like a chain.... each if code starts another little chain part which affects the outcomes of different elses... i did not know that thanks