Grading Program Confusion

Okay Im a newbie and Im working on a program that allows the user to enter a grade (0-100) and then the console returns to the user the grade and the letter of the grade. This is what i have and so far I have only programmed grades 70 and up. Here's my problem: if the grade is 90 or above, the console displays "A".. which is fine. But when I enter a grade that is less than 90 and above 80, the console displays "AB".. then when I enter a grade above 70 and less than 80 the console displays "ABC".. this program is supposed to return grades, not teach me my ABCs. Please help and let me know if I am approaching this program completely wrong. Here's what I got:

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
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>

using namespace std;

int main()
{
    bool P, A, B, C, D, F;
    P = false;
    A = false;
    B = false;
    C = false;

    int grade;
    cout << "Enter Grade:\n";
    cin >> grade;
    if (grade == 100)
    {
        P = true;
        if (P = true)
        {
            cout << "Perfect Score!";
        }
    }
    if (grade >= 90, grade < 100)
    {
        A = true;
        if (A = true)
        {
            cout << "A";
        }
    }
    if (grade >= 80, grade < 90)
    {
        B = true;
        if (B = true)
        {
            cout << "B";
        }
    }
    if (grade >= 70, grade < 80)
    {
        C = true;
        if (C = true)
        {
            cout << "C";
        }
    }

    return 0;
}
1
2
P = true;
        if (P = true)

just leave that away. since it is useless. and you shouldn't use a , for the if's:
(grade >= 80, grade < 90)
should become
(grade >= 80&& grade < 90)
EDIT: actually just leave second part away and use else if statements like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (grade == 100)
    {
            cout << "Perfect Score!";
    }
    else if (grade >= 90)
    {
            cout << "A";
    }
    else if (grade >= 80)
    {
            cout << "B";
    }
    else if (grade >= 70)
    {
            cout << "C";
    }
Last edited on
Topic archived. No new replies allowed.