I'm writing a console application for a C++ course and it requires us to use a loop to have the user input a name, city, and 5 scores. This is the section of code I'm having problems with. I've narrowed it down by putting it in it's own application and testing it there. What happens when I run this code is that on the first iteration of the while loop it outputs:
enter name: i
enter city: i
redo? y
enter name: enter city:
The i in italic represents user input. It will change the string city if I input something after the redo line, but it just clears the string name. Any help?
Nothing in that thread helped me to solve my problem or even better understand it. It actually made me more confused because from what I understood of the original post was that they were having pretty much the same problem I am, but the answers they received solved their problem but didn't work for mine. I've read everything I could find about the getline(); function, as well as the cin.ignore();.
Well technically the stream size max is 2147483647 ( for some reason has a minimum of -2147483648 not sure why... how can you stream negative characters?) so might be a little more accurate to do std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n' );
in case the user inputs more than 100 characters.
EDIT: it says that streamsize is a signed value so not sure why the min would be a negative value? meh oh well..