what am i missing in my code?

i had to make a code for a GPA converter. every thing works fine when I put in a number like 83. But when I input a number with a decimal like 83.5 it prints out the else message for me. What am I missing?

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
52
53
54
55
56
57
58
  #include <iostream>
#include <string>
using namespace std;

int main()
{

    float grade;
    cout.precision(2);

    cout << "GPA Conversion" << endl;
    cout << "--------------" << endl;
    cout << "Enter your grade: ";
    cin >> grade;
    cout << endl;

    if ( grade <=100 && grade  >=96)
        cout << "You will receive a letter grade of A with a 4.00 GPA.";

    else if ( grade <=95 && grade  >=90)
        cout << "You will receive a letter grade of A- with a 3.70 GPA.";

    else if ( grade <=89 && grade  >=87)
        cout << "You will receive a letter grade of B+ with a 3.30 GPA.";

    else if ( grade <=86 && grade  >=84)
        cout << "You will receive a letter grade of B with a 3.00 GPA.";

    else if ( grade <=83 && grade  >=80)
        cout << "You will receive a letter grade of B- with a 2.70 GPA.";

    else if ( grade <=79 && grade  >=77)
        cout << "You will receive a letter grade of C+ with a 2.30 GPA.";

    else if ( grade <=76 && grade  >=74)
        cout << "You will receive a letter grade of C with a 2.00 GPA.";

    else if ( grade <=73 && grade  >=70)
        cout << "You will receive a letter grade of C- with a 1.70 GPA.";

    else if ( grade <=69 && grade  >=67)
        cout << "You will receive a letter grade of D+ with a 1.30 GPA.";

    else if ( grade <=66 && grade  >=64)
        cout << "You will receive a letter grade of D with a 1.00 GPA.";

    else if ( grade <=63 && grade  >=60)
        cout << "You will receive a letter grade of D- with a 0.70 GPA.";

    else if ( grade <=59 && grade  >=0)
        cout << "You will receive a letter grade of F with a 0.00 GPA.";

    else
        cout << "You have not entered a grade between 0 and 100. Ending program.";


return 0;
}
Thats because 83.5 is not covered in your conditions. You have an option for >=84 and an option for <=83 but nothing between 83 and 84. Thus, when 83.5 is entered, it is neither >= 84 nor is it <= 83.

So you need to fix your conditions so every decimal is covered.
Last edited on
Thats because 83.5 is not covered in your conditions. You have an option for >=84 and an option for <=83 but nothing between 83 and 84. Thus, when 83.5 is entered, it is neither >= 84 nor is it <= 83.

So you need to fix your conditions so every decimal is covered.


i figured that was it. been troubleshooting for 2 hours on how to include every decimal and havent made any progress. it seems so simple
Topic archived. No new replies allowed.