invalid output help

i made a program that gives you a letter grade and average when you enter a number from 0 to 100. I'm missing one piece where the user inputs a number outside of 0 to 100. the output is suppose to look like this

Example output 1 (invalid input, input is in bolded italics):
GPA Conversion
- - - - - - -
Enter your grade: -10.2
You have not entered an grade between 0 and 100. Ending program.

every code i tried doesn't result in what im suppose to get above if i put an invalid number.




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
  #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.";

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

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

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

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

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

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

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

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

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

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

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






    return 0;
}
1
2
3
4
if (grade < 0) {
cout << "You entered an invalid grade. Please enter a new one: " << endl;
cin >> grade;
}
grade should be an unsigned int, at the moment what happens when one enters 95.5? The program ends.

I second his comment^
Topic archived. No new replies allowed.