I'm trying to a simple ticketing machine program. I prompt for user input in integer form because my assignment forced to be so. So i write as follow:
Yet, problem occured when i testing the program.Code:#include <stdio.h> int main (void) int departure, destination; printf("Please enter your destination [0-10]: "); scanf("%d",destination); while (destination<0 || destination>10) { printf("Error! Please enter appropriate destination."); printf("Please enter your destination [0-10]: "); scanf("%d",destination); }
If the user enter character as input, then my program will keep on non-stop poping out my "loop part".
It just would be fine when key in integer but it will error when users entering character. So, how m i going to prevent it non-stop poping out error when users entering character ???



LinkBack URL
About LinkBacks



