that grading program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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;

}


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?
Look at line 17. You're missing an else.
hmmm your right that fixed it, though since it worked doesnt it mean i can use if as many times as i want? or does that make stuff unstable?
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
Topic archived. No new replies allowed.