Open Source Development Tutorials | Newsletter Signup | About Us
Search  

Go Back   Open Source Tutorials Forum > Programming Languages > C and C++ Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-14-2007, 09:10 PM
patrick66 patrick66 is offline
Junior Member
 
Join Date: Dec 2007
Posts: 1 patrick66 is on a distinguished road
Default cin bypassed by wrong input

Hello All,
When I key in 'r' for int num, the value for num is something like
-895784932. This cause the subsequent cin >> choice to be ignored by the program. If I key in a small negative, say -5 then cin >> choice (char) is executed. How do I amend the code so that cin >> choice is executed for any input for num? What was the problem for the current failure?
Thanks.

The code segment:
cout << "Enter a positive number " << endl;
cin >> num;
while (num <= 0 && quit == false) {
fflush(stdin);
system("CLS");
cout << "The number you entered is not positive. Reentered(Y/N)?\n";
cin >> choice;
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 07:20 AM.


Powered by: vBulletin Version 3.0.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright 2004 - 2006 GrindingGears.com. All Rights Reserved.