Hello Slyde,
But this has even more confused: others have tested the code and they say it works for them. Is this a compiler thing?
|
That makes 2 of us. The question to ask is what compiler they used or where they compiled and ran the program. Was it their computer or onlike?
There are 2 types of input; formatted and unformatted. Formatted input something like:
std::cin >> menuChoice;
will take what you type and put it into a buffer, usually referred as the input buffet, and wait until you press "Enter". Then it will attempt to put you input into the variable, but it leaved the new line (\n) in the buffer. If followed by another
std::cin >> something;
this is not a problem because the "std::cin" will ignore any white space including the (\n).
The unformatted input, the "std::getline()" will extract the entire contents of the buffer including the (\n) which it discards leaving the buffer empty.
So when your program mixes formatted input with unformatted input you can usually follow the input with
std::cin.ignore();
. This will ignore the (\n) left in the buffer. If it should be a problem the line I showed you is considered the most portable way.
Sometimes when you are not sure where the last formatted input is putting the ignore before the "std::getline" works.
Given your menu code try using "std::cin.ignore():" after line 6 or 7 and see what you get.
Andy