| www.delorie.com/archives/browse.cgi | search |
| From: | gehok55 AT hotmail DOT com (Josh) |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | user input problem |
| Date: | Fri, 12 Oct 2001 19:51:06 GMT |
| Message-ID: | <3bc7498f.24352957@news.westnet.com.au> |
| X-Newsreader: | Forte Free Agent 1.21/32.243 |
| NNTP-Posting-Host: | dsp-202-72-132-14.perth.westnet.com.au |
| X-Trace: | quokka.wn.com.au 1002970247 dsp-202-72-132-14.perth.westnet.com.au (13 Oct 2001 03:50:47 +0800) |
| Lines: | 22 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
why does this code get stuck in an infite loop after the user enters
in a character instead of an integer.
I tried doing a cast in the scanf, but i think i was doing it wrong
--------------------------------------------------------
int numplayers;
//check valid number of players
printf("\n\nPlease enter the number of players [2-4]: ");
scanf("%d",&numplayers);
while (numplayers < 2 || numplayers > 4) {
printf("\n\tScarbble requires between 2 to 4 players..");
printf("\n\nPlease enter the number of players [2-4]: ");
scanf("%d",&numplayers);
}
-----------------------------------------------------------
any help is greatly appreciated
-Aek
aek AT wn DOT com DOT au
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |