Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Skipping cin
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AnubisProgrammer




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
paul03




PostPosted: Fri Jun 03, 2005 9:50 am   Post subject: (No 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.
AnubisProgrammer




PostPosted: Fri Jun 03, 2005 11:41 am   Post subject: (No 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.
Tony




PostPosted: Fri Jun 03, 2005 12:11 pm   Post subject: (No 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.
AnubisProgrammer




PostPosted: Wed Jun 08, 2005 11:57 am   Post subject: (No subject)

thanks a lot, that's what my problem was I think. My program is working now.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: