I'm trying to learn programming from a book. In one drill I am expected to use a while loop to ask for and return two integers. To end the loop the user is expected to enter a '|' character. I have a prompt to ask continue or enter the '|' key to end. The program works okay until the enter key is used to indicate whether or not to continue. When enter is pressed, the cursor moves down a line but waits for the '|' key. I tried an if statement to watch for a '\n' and '\r', and I believe is tried '\n' keystrokes, but nothing goes into the char variable controlling the loop. Could I be using the wrong characters for the return key? Is the return character specific to the compiler?
You can't enter '\n' or '\0' through std::cin operator>>, so your method isn't going to work.
You want '|' to end the loop, so why even check for '\n' or '\0'?
1 2 3 4 5
while (again != '|')
{
cin >> again;
}
std::cout << "out of loop!" << std::endl;
What exactly do you want to happen if the user only presses Enter/Return at the "Enter | to end" prompt?
I think answering that will help us help you.
Also, you must put the code between the [code] delimiters -- between the ] and [, not inside the delimiters themselves.
Thank you for the reply. The reason I am checking for the '\0' and '\n' characters is because I am not sure which would be read as the return character. Entering return at the "Enter | to end" prompt should allow the loop to continue.