In: Computer Science
Create a C++ program that will accept any number of grades for an exam. The grades will be input as 4 for an A, 3 for a B, 2 for a C, 1 for a D, and 0 for an F. After all grades have been entered, allow the user to enter -1 to exit. Output the number of grades in each category. Using arrays.
#include <iostream>
using namespace std;
int main() {
int grades[5] = {0, 0, 0, 0, 0}; // declaring grades for
ABCDF
char letters[5] = {'F', 'D', 'C', 'B', 'A'}; // grades
int g; // taking input of a grade
cout << "Enter grades one by one (-1 to stop):\n";
cin >> g;
while(g != -1) // as long as grade is not -1, taking input
{
grades[g]++; // incrementing the respective grade by 1
cin >> g;
}
for(int i=4; i>=0; i--) // printing output
cout << endl << "# of Grade " << letters[i]
<< "'s: " << grades[i];
}
// -------- Hit the thumbs up if you are fine with the answer. Happy Learning!