endless loop...
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
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)
without knowing, all i can say is check the input before proceeding, and if it is not correct ask again.
--- krez (krezisback@aol.com)
using C++
// Ask player to bet - must be >= 2 or <= pot do { cout << "Enter bet: "; cin >> bet; } while ( bet < 2 || bet > pot );
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
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
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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement