I need some help. I want this program to ask the user how many grades they would like to enter. Than when the user inputs it should ask for the prompt enter your grades as many times as the user wanted. Than assign each letter to the number of grades. When i run the application i can only enter one grade and it assigns it to "The number of A's is:". Here is what i have so far

// may 10 2010

#include <iostream>
using namespace std;

int main ()
{
	int numberGrades;
	int gradeCount[5] = {0};
	char letterGrade;

	cout << "How many grades would you like to enter? ";
	cin >> numberGrades;

	for (int count =0; count <= numberGrades; count++);
	{
		cout << "Enter the grade ( A, B, C, D, E): ";
		cin >> letterGrade;

		switch (letterGrade)
		{
		case 'A':
		case 'a':
			gradeCount [0]++;
			break;
		case 'B':
		case 'b':
			gradeCount [0]++;
			break;
		case 'C':
		case 'c':
			gradeCount [0]++;
			break;
		case 'D':
		case 'd':
			gradeCount [0]++;
			break;
		case 'E':
		case 'e':
			gradeCount [0]++;
			break;
		default:
			cout << "\aInvalid letter grade!\n";
		}//end switch
	} // end for

	letterGrade = 'A';
	
	for ( int index = 0; index <5; index++)
	{
		cout << "\nThe number of " << letterGrade << "'s is: " <<gradeCount[index];
		letterGrade++;
	}// end for
	
	cout << endl << endl;
	return 0;
}

Looks like you need to increment gradeCount[0] as you've done for 'A', but gradeCount[1] for 'B' etc, rather than gradeCount[0] each time.

Dave

ok but how do i get the question "Enter the grade ( A, B, C, D, E): "; to repeat the same number of times as the user requested

You had me confused for a minute, but you have a classic mistake! Remove the semicolon at the end of the for statement:

i.e. change this

for (int count =0; count <= numberGrades; count++);

to this:

for (int count =0; count <= numberGrades; count++)

Dave

Thanks Dave...even i got confused for a moment.

Thank you for your help. Sorry about the private message I am new to the site and just getting use to everything.

You had me confused for a minute, but you have a classic mistake! Remove the semicolon at the end of the for statement:

i.e. change this

for (int count =0; count <= numberGrades; count++);

to this:

for (int count =0; count <= numberGrades; count++)

Dave

Also

for (int count =0; count < numberGrades; count++)

will prompt the user for the correct number of grades.
The program was prompting for one more than the number the user had entered due to the zero-based start of the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.