I can't figure out this program

I need help repeating the Enter students name and grade while q is not entered. I'm not sure what loop to use.

I'm confused on how to use the switch statement for the IF statement.

Also, I can't figure out how to output how many students got which grades.

Here's the code so far:

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/********************************************
 This program should take users name
 and grade and output their name, grade
 and letter grade. Then it should repeat
 this until "q" is entered. Then tells how
 many students their are and how many students
 got a certain grade.
 ********************************************/

#include <iostream>
#include <string>

using namespace std;

char getScore()
{
    char studentScore = 0;
    int score1;
    
    if (studentScore <= 100) 
    {
        score1 = 'A';
    }
    else if (studentScore <= 89)
    {
        score1 = 'B';
    }
    else if (studentScore <= 79)
    {
        score1 = 'C';
    }
    else if (studentScore <= 69)
    {
        score1 = 'D';
    }
    else if (studentScore <= 59)
    {
        score1 = 'F';
    }
    else if (studentScore < 0)
    {
        cout << "Please enter a number between 0 and 100" << endl;
    }
    else
    {
        cout << "Invalid entry";
    }
    return score1;
}

int main()
{
    string student;
    char score;
    int studentScore;
    int score1;
    bool q = true; // if user enters q, q is is true
    
    cout << "Enter q to see stats of grades" << endl;
    cin >> q;
    cout << "Enter your name: ";
    cin >> student;
    cout << "Enter your score: ";
    cin >> studentScore;
    
    
    
    
    score = getScore(); // Go to function getScore
    
    while (!q)
    {
        cout << "Student " << student << " has a grade of " << studentScore <<
        " and letter grade: " << score;
    }
    
    
    return 0;
}
Last edited on
Topic archived. No new replies allowed.