GPA Calculator

I'm trying to make a GPA calculator where the user inputs a letter grade including a plus or minus but I cannot figure out where to start. So far I have prompted the user for inputs. I need to make it so when someone enters an 'A-' then the program states the gpa is a 3.7 whats my next step

1
2
3
4
5
6
7
8
9
10
11
12
  
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string grade;
    int credits;
 
    cout << "Enter a grade letter and the corresponding number of credits: " << endl;
    cin >> grade >> credits;
I now have created switch cases but i cannot figure out how to have inputs like A- or B+

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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    char grade;
    int credits;
 
    cout << "Enter a grade letter and the coreesponding number of credits: " << endl;
    cin >> grade >> credits;
    
    cout << grade << endl;
    
    switch(grade)
    {
        case 'a': cout << "Your GPA is a 4.0 \n";
            break;
        case 'b': cout << " Your GPA is a 3.0 \n";
            break;
        case 'c': cout << "Your GPA is a 2.0 \n";
            break;
        case 'd': cout << "Your GPA is a 1.0 \n";
            break;
        case 'f': cout << "Your GPA is a 0.0 \n";
            break;
        default: cout << "Invalid Input";
Well to start, a char value is a single character.
You want to enter A- which are 2 chars'.
You could try and figure out how to reach each char into a value but I would change it to a string and read in the whole line.

Topic archived. No new replies allowed.