Hi everyone. I have a problem with switch - case structure. Actually , this program almost works as i want , but the only problem is that if smo enters a character as a question number , the program closes down . However , i just want to see the "ERROR.. " message when whatever i enter except for [1 . . . 10] . Is there anyone helping me ?
Code:#include <stdio.h> #include <conio.h> int main (void) { int qnumber,i; for (i=0;i<1000;i++) { printf("Please enter the question number : "); scanf ("%d",&qnumber); switch (qnumber) { case 1: printf ("Question 1\n"); continue; case 2: printf ("Question 2\n"); continue; case 3: printf ("Question 3\n"); continue; case 4: printf ("Questin 4\n"); continue; case 5: printf ("Question 5\n"); continue; case 6: printf ("Question 6\n"); continue; case 7: printf ("Question 7\n"); continue; case 8: printf ("Question 8\n"); continue; case 9: printf ("Question 9\n"); continue; case 10: printf ("Question 10\n"); continue; default: printf ("ERROR!! There is no question like this.\n"); continue; } } getch (); return 0 ; }



2Likes
LinkBack URL
About LinkBacks


