![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 1
| Here is the part that I am having trouble with. Code:
#include <stdio.h>
int main ( ) {
int veh;
printf("\nDo you have a car? (1:Yes, 2:No): ");
scanf("%d", &veh);
while (veh < 1 || veh > 2) {
printf("Please select 1 for Yes or 2 for No: ");
scanf("%d", &veh);
}
return 0;
}
The problem is is that when I type in a letter instead of a number, it displays a wall of "Please select 1 for Yes or 2 for No: ". Is there a way to fix this? Thanks |
| redened is offline | |
| | #2 |
| Registered User Join Date: Oct 2006 Location: Canada
Posts: 848
| reading input is a common beginners problem, see FAQ: How do I get a number from the user (C) |
| nadroj is offline | |
![]() |
| Tags |
| loop, problem, programming |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Poll event loop | rogster001 | C++ Programming | 2 | 09-17-2009 04:28 AM |
| need help with a loop | Darkw1sh | C Programming | 19 | 09-13-2009 09:46 PM |
| funny-looking while loop | Aisthesis | C++ Programming | 3 | 08-30-2009 11:54 PM |
| nested loop, simple but i'm missing it | big_brother | C Programming | 19 | 10-23-2006 10:21 PM |
| loop issues | kristy | C Programming | 3 | 03-05-2005 09:14 AM |