Hello gradePerc,
Since you asked for all help.
Your first bit of posted code has problems.
Line 2 is missing the semi-colon.
The comment on line 4 is nice, but should be part of the prompt. Playing with the program I did this:
std::cout << "\n Enter the letter and grade (A 95) for class " << count + 1 << ": ";
The "\n " at the beginning of the string is optional, it makes it easier for me to read the screen. The end of the string, (for class) and the "count + 1" is just a help and is also optional. The "(A 95)" is what you really need. Even with that you are likely to get some people enter the letter and pressing enter. I would consider making each variable a separate input with its own prompt.
As
dutch pointed out and in case you did not know.
cin >> letterGrade
is formatted input which means that the keyboard input goes into the
input buffer until you press "Enter". When "Enter" is pressed the program will extract from the input buffer up to a white space or new line whichever comes first. So as
dutch is saying
cin >> letterGrade
will extract up to and including the space then disgacd the space leaving the pointer at what is next and putting the letter into "letterGrade".
Now when formatted input it to a numeric variable "cin" is expecting a number. So anything other than a number will put "cin" into a failed state that would need to be dealt with. This failure can be caused by enter anything that is not considered a number like: a letter, punctuation character, including a decimal point as in .125. This will set one or more of the state bits making "cin" unusable the rest of the program unless fixed.
In the do/while loop you should include the prompt. otherwise the output to the screen would look like this:
How many classes are you taking?: 2
// The comment in the code is nice, but should be included in the prompt.
Enter the letter and grade: a 95 // First run through the loop.
//< cursor is here. What to enter. No idea.
b 85 // second time through loop.
//< cursor is here. What to enter. No idea.
c 70 // Third time through loop, but only wanted 2.
|
The code you have posted and when run leaves a lot of guess work.
Be careful when using "<=". In the while condition it causes it to loop three times. One more than it should. Unless you initialized "count" to (1) and it does not show in the code posted.
Hope that helps,
Andy