|
![]() |
|
Thread Tools | Display Modes |
|
![]() |
#1 | ||
![]() ![]() ![]() ![]() ![]() Join Date: May 2009
Location: Olean, United States
Posts: 20
|
![]() EL Quia is correct in their response. Validating the user input is always a requirement.
To expand upon the answer, when the user of your program enters a character into the iostream object(cin) of type int, the int is filled with garbage data and the failbit of the iostream object is set to true. Until the iostream object failbit is cleared and the data in the cin stream is dicarded, your cin is unusable and will not get user input again, hence your infinite loop. Here is an example of something similar to what you might want to try: Code:
unsigned short int taketarget (unsigned short int records) { int target=0; while (target<1 || target>records) { cout << "\nEnter target record number:\n"; cin >> target; if (cin.fail()) { cout << "Invalid Input." << endl; cin.clear(); cin.ignore(); cout << "Enter a number between 1 and " << records << ".\n"; } } return target; } |
||
![]() ![]() |
|
![]() |
#2 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
![]() Thanks, Acero. This solved the problem perfectly.
|
||
![]() ![]() |
|
![]() |
#3 | ||
![]() ![]() ![]() ![]() ![]() Join Date: May 2009
Location: Olean, United States
Posts: 20
|
![]() |
||
![]() ![]() |
|
![]() |
#4 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
![]() A tool to convert sprites from Space Hulk's non-standard format to PCX.
|
||
![]() ![]() |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Killer Loop [SOLD] | Paco | Rejected requests | 2 | 04-08-2011 04:47 PM |
X-COM 1 (UFO) Saving game locks up - Dosbox | Thraka | Troubleshooting | 3 | 19-06-2008 12:10 AM |
Infinite Dungeons For Nwn | Lucullus | Gaming Zone | 13 | 20-06-2006 12:23 PM |
Gauntlet 2 System Loop | insidious | Troubleshooting | 7 | 18-05-2006 08:49 AM |
Eternam - computer locks up | wendymaree | Troubleshooting | 6 | 02-08-2004 08:43 AM |
|
|
||
  |