hello, I'm somewhat new to programming in C++ and have been given the task of writing a program that inputs letter grades, however I am having a difficulty inputting the number of grades that are A, B, etc. Please take a look and help me out
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int letter_grades = 50; //Number of Letter Grades
int count;
char letters[letter_grades] ;
int num_grade;
cout << "How many letter grades are there?" << endl;
cin >> num_grade;
//Input the Number of times the letter grade showed up
for (count = 0; count < num_grade; count++)
{
cout << "Enter grade "
<< (count + 1) << ": ";
cin >> letters[count];
}
//Display the all the grades
cout << "The grades you entered aer... " << endl;
cout << "Letters" << "\t" << "Number of times entered\n";
cout << "-------" << "\t" << "-----------------------\n";
for (int count = 0; count < num_grade; count++)
{
cout << letters[count] << "\t\t";
cout << letter_grades << endl;
}
Sorry i really have no idea, I just spent the last hour reading it up in this beginner C++ book but I'm not understanding something. I was thinking of doing something like this model inside the for loop:
Ok well if you've ever tallied something on paper (by hand, not with a program)
you know your paper looks something like this when you start.
A:
B:
C:
D:
F:
So let's start our program by creating a place in memory for each grade.
1 2 3 4 5 6 7
int numOfA = 0,
numOfB = 0,
numOfC = 0,
numOfD = 0,
numOfF = 0;
//Why int's? Because a tally chart starts at 0 and adds 1 over and over.
// So we only need (unsigned) integer precision here.
Now after we ask the user for a grade, we need to tally in the correct place based on the input.
1 2 3 4 5 6 7 8 9 10 11 12
//grade has the input (type char)
switch(grade) {
case'A': case'a':
numOfA++; //tally numOfA's (increase by 1)
break;
case'B': case'b':
numOfB++;
break;
//etc...
default:
//not a vaild grade
}
I'll leave the rest up to you.
Let me know if you still can't figure it out...