letter grades

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;
}

system("pause");
return 0;
}
You almost have it. The problem is you are storing all the letter grades in an array and then redisplaying each one.

Think about how you would "tally" letter grades on paper... Like if I gave you the grades
B, B, C, A, F, C, B, A, B, C

You should get
A: II
B: IIII
C: III
D:
F: I


So now how can you make a program that mimics that algorithm?
Last edited on
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:

{
cout << "Letter Grade" << (count + !) << "has ";
cout << letters[count] << " grades." << endl;
}
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...
Last edited on
hello, sorry for not posting earlier, thank you I was able to get it.
Topic archived. No new replies allowed.