Problem with the return on a function

The object of this code is to simply take in a grade percentage like 90 and return a letter grade like A. The below code works on all floats given to it but not on whole numbers. I don't know why. Any help would be great!
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
  #include <iostream>

using namespace std;


string grade(float GPA);

int main()
{
    float GPA;
    cout <<"Enter your percentage:\n";
    cin>>GPA;
    cout <<"Letter grade:"<<grade(GPA);
    return 0;
}


string grade(float GPA)
{
    if(GPA>100.00 || GPA<0.00)
    {
        return " Invalid percentage\n";
    }
    else if (GPA>90.00 && GPA<100.00)
    {
        return " A\n";
    }
    else if (GPA>80.00 && GPA<90.00)
    {
        return " B\n";
    }
    else if(GPA>70.00 && GPA<80.00)
    {
        return " C\n";
    }
    else if (GPA>60.00 && GPA<70.00)
    {
        return " D\n";
    }
    else if (GPA<50.00)
    {
        return " F\n";
    }
}
Look closely, and you'll notice that none of your conditions actually account for whole numbers since you always check strictly less than or strictly greater than. So, for example, 90 would not fall into A because it is not >90, nor would it be in the B range because it is not <90.
Thank you so much!!!! I added all the equal signs to the code and it works perfectly. Thanks for having good eye for detail!!! Thank you
Topic archived. No new replies allowed.