#### Archived

This topic is now archived and is closed to further replies.

# endless loop...

This topic is 6094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I ask my user for a bet, it must be greater than or equal to 2, or less than or equal than their pot. Let's say they enter a character. BAM! Endless loop! How do I fix this? Or they enter some number like 999999999999999999999999999999 Edited by - random-decay on October 14, 2001 2:46:20 AM Edited by - random-decay on October 14, 2001 2:48:51 AM

##### Share on other sites
um, you gotta be more specific... what programming language? how are you getting this input? etc...
without knowing, all i can say is check the input before proceeding, and if it is not correct ask again.

--- krez (krezisback@aol.com)

##### Share on other sites
using C++

  // Ask player to bet - must be >= 2 or <= pot do { cout << "Enter bet: "; cin >> bet; } while ( bet < 2 || bet > pot );

##### Share on other sites
How is bet declared? How is it being read? If bet is a char then it may always fall outside your range and thus loop indefinitely. I suggest you run your program through the debugger (if you don't know how to use the debugger, this is a good time to learn!)

You also have the interesting logic bug of doing a logical OR rather than an AND in your condition statement.

Edit: if your user enters a character, it may convert to its ASCII equivalent in integer context (ah, Perl...)

Edited by - Oluseyi on October 14, 2001 4:04:24 AM

##### Share on other sites
Try using this. There''s probably a better way of doing it but it should work for now.

  int bet = 0;BOOL betOK = FALSE;while (!betOK){ cout << "Enter bet: "; cin >> bet; if ((bet >=2) && (bet <= pot)) betOK = TRUE;}

• 17
• 11
• 15
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999765
×