Logic Error

I am trying to work my way through this series of exercises:
http://www.cplusplus.com/forum/articles/12974/

I'm stuck on the first one. (Stop laughing.) The program is supposed to take the input of a number grade and turn it into a letter grade. I think I'm close, but I'm missing something. No matter what number I put in, I get a result of 'A.'

Here's the code:
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
59
60
61
62
#include<iostream>
using namespace std;

//Declare functions
int getNumberGrade();
char getLetterGrade(int);
void displayGrade(char);

int getNumberGrade()
{
    
    int numberGrade;
    cout << "Please enter your grade: ";
    cin >>numberGrade;
    getLetterGrade(numberGrade);
    
}

char getLetterGrade(int numberGrade)
{
     
     char letterGrade;
     if (numberGrade == 100)
     {
          cout << "Curve Buster! Perfect score." << endl << endl;
          letterGrade = 'A';
     }
     else if (numberGrade >= 90 || numberGrade <= 99)
     {
          letterGrade = 'A';
     }
     else if (numberGrade >= 80 || numberGrade <= 89)
     {
          letterGrade = 'B';
     }
     else if (numberGrade >= 70 || numberGrade <= 79)
     {
          letterGrade = 'C';
     }
     else if (numberGrade >= 60 || numberGrade <= 69)
     {
          letterGrade = 'D';
     }
     else if (numberGrade < 60)
     {
          letterGrade = 'F';
     }
     
     displayGrade(letterGrade);
     
}

void displayGrade(char letterGrade)
{
     cout << endl << "Your Grade: " << letterGrade << endl << endl;
}

int main()
{
    getNumberGrade();
    return 0;
}


Thanks in advance for your help.
|| is the logical or operator, so numberGrade >= 90 || numberGrade <= 99 is always true.
If numberGrade >= 90 is false, then the grade is <90 - therefore the second condition will be true.
Thank you. <face palm>

EDIT: Quick change fron || to && and it's working. Thanks again.
Last edited on
Topic archived. No new replies allowed.