Write a program that reads in letter grades for a class of 20 students and displays
the number of students who passed (D or better) and the number who failed. (F)
How do I get the it to cout the students who passed or failed?
Thanks.
In addition to SamuelAdams suggestion you are missing "break;" statements in the case statements. Although what you have will work it gives you incorrect totals for pass and fail. Also the "default" case should not be an addition to "fail", but a message saying something about the wrong letter being entered along with subtracting 1 from "i" to give the user a chance to reenter the grade.
I would also consider moving line 7 to line 11.
You could also write the switch as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
switch (X)
{
case'A':
case'B':
case'C':
case'D':
pass++;
break;
case'F':
fail++;
break;
default:
std::cout << "Invalid Entry. Choices are: A B C D and F";
i--; // Allows the user to correct the invalid entry.
} // end switch
A Shorter way to write the switch, but still works the same.