Skipping input?

Pages: 12
it still wants to go to the debug before I have a chance to input
If anyone else can help, itd be greatly appreciated
then I guess its skipping the getline line completely at first,
Nope, the computer will do exactly as you tell.
What is happenning is that you've got an '\n' that remains in the buffer, so when getline reads, it reads till the end of line (it reads nothing in this case).
Try in.ignore(); or in.ignore( numeric_limits<streamsize>::max(), '\n' );
would I put that before the getline line? I'll try that then
Don't srand() anywhere but somewhere at the top of main().

Lines 28 and 36 do the same things. Change 36 to } while (true);. (You don't technically need line 32 either.)

Line 75 tests something that you already know as a consequence of line 44. All you need is an else.

The problem you are having is that somewhere else in your program you are not clearing the newline from the user's input before you call this function again.

Remember: the user will always press ENTER at the end of every input.

As a consequence, you must always get rid of the newline in the input after the user gives you input. http://www.cplusplus.com/forum/beginner/20577/#msg107828

Hope this helps.
It works for the first time it goes through the loop, but after that, no matter what I put (even if its legal) It will say Nope. Try Again.
Actually you should put that right after you do the in>>var;
(or use something like
1
2
while( getline(in, line) and line=="" )
 ; // <-- do nothing 


Before line 25, it should work
But if the user presses enter only once, then why would it be residual? and why doesnt it mess up at any other part of the code?
You aren't paying attention. The problem isn't in your function. It is that somewhere else in your program you are leaving a newline in the input after getting something from the user. Find that and fix it.
How can I identify where a newline is being left in the input?
And if that were true, wouldnt the same thing happen with cin >>?
Nope, because the operator>> ignores whitespaces http://cplusplus.com/reference/iostream/manipulators/skipws/
"if that were true"?
I'm not the know-nothing troglobite asking for help, but ignoring all the information feed him.
Bye.
I tried using the cin.ignore( numeric_limits <streamsize> ::max(), '\n' ) line before every input, and it solved the line being displayed where I didnt want it, but now I have to type in the command 2 times everytime I want to do something
Last edited on
@Duoas: Yeah, sorry, that came out wrong DX
hmm... Actually, I put it only where the residual newline seemed to be actually affecting it, and it seems to work fine now
Sorry to have been grouchy. I'm glad you got it figured out.
Ehh, dont worry about it, I guess I probably should have paid more attention to the whole residual newline thing :P I just didnt really understand it though xD
Topic archived. No new replies allowed.
Pages: 12