Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 02-12-2009, 10:07 PM   #1
The Fifth Horseman
FUTURE SCIENCE BASTARD
 
The Fifth Horseman's Avatar


 
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
Default Function locks into an infinite loop: why?

Okay, I have a program that moves across a bunch of records stored into memory and reports information about each (number, adress, some initial values).
Full sourcecode


It (mostly) works, but the following function doesn't work as intended.
Code:
unsigned short int taketarget (unsigned short int records)
     {  
        int target=0;
        cout << "\nEnter target record number:\n";
       while (target<1 || target>records)
         { cin >> target;
         if (target<1 || target>records)
           { cout << "Enter a number between 1 and " << records << ".\n"; }
         }
        return target;
     }
It's supposed to keep prompting the user until valid input is entered.
It does just fine if the user enters numeric values - but if a character is entered, the function loops infinitely without giving the user any way to enter new input.

What may be the cause of this behavior?
__________________

"God. Can't you people see I'm trying to commit a crime against science and nature here?"
-- Reed Richards
The Fifth Horseman is offline                         Send a private message to The Fifth Horseman
Reply With Quote
 


Similar Threads
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


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

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


The current time is 02:24 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.