Computer Science Canada

Skipping cin

Author:  AnubisProgrammer [ Fri Jun 03, 2005 9:19 am ]
Post subject:  Skipping cin

I'm writing a program, it's going really well until it hits one point. I'm running functions, and using cin statements, but in one of my functions, for no reason it skips the cin statement completely. Here's the code:

cout<<"What do you wish to do?\n";
cout<<"1-Move 2-Hunt 3-Rest 4-Move To\n";
cin>>atrest;

there's some statements afterwards depending on what the user inputs in the cin, but it doesn't matter, the variable (atrest) is auto set to 0 and the cin is skipped completely, which ends my program. Has anyone else had this problem or know how to fix it?

Author:  paul03 [ Fri Jun 03, 2005 9:50 am ]
Post subject: 

Is there a cin statement before this?
If so, the program might have taken a part of previous input as "atrest" and skipped it.

Author:  AnubisProgrammer [ Fri Jun 03, 2005 11:41 am ]
Post subject: 

I am using cin statements before but atrest is a new variable. Could it have to do with running out of resources? The program has a lot of variables in it. All the cin statements work but this one.

Author:  Tony [ Fri Jun 03, 2005 12:11 pm ]
Post subject: 

AnubisProgrammer wrote:
I am using cin statements before but atrest is a new variable.

Confused I don't think you understand

What you type into the keyboard is buffered and waits to be read. Sounds like you have some junk remaining to be read.

It's a good practice to clear the input buffere before prompting user for a new responce.

Author:  AnubisProgrammer [ Wed Jun 08, 2005 11:57 am ]
Post subject: 

thanks a lot, that's what my problem was I think. My program is working now.


: