You are storing
name in a
char, which can contain exactly one character. So, if you try to type any more than one character, say, "Bobby",
name will have the value
'B' and the input stream will still have
"obby" waiting for input.
When you come to line 18,
cin takes your input stream (
"obby") and tries to turn it into an
int, which it can't. This sets a failure flag, so from then on calling
std::cin will fail automatically, meaning your
while loops never finish.
Luckily, there is an easy fix: change line 9 so that
name is of type
std::string rather than
char; this will allow it to take more than one character. Also, you can clear the failure flag so that even if the user gives letters rather than numbers, your program won't just die:
1 2 3 4 5 6 7 8 9 10
|
#include <limits>
//...
while (testOne > 0 && testOne <= 100) {
// ignore the rest of the input stream
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
// clear the error flag
std::cin.clear();
// ...
}
|
EDIT:
You changed your variable names while I was typing up my answer... Make sure that you type them right (i.e.
gradeTwo rather than
gradesTwo)