I'm in grade 9, so still new to C. Can anyone tell me how to do this? When someone enters a value greater than 4, then he should print the label βdefault:β of the case switch statement. I tried to use time for this, but he gave errors. Code
#include <stdio.h> #include <unistd.h> void main() { int n1,n2,a=0,c,r,o; S: printf("\n \n 1. Addition \n 2. Substract \n 3. Multiply \n 4. Divide \n \n"); printf("\n Enter your choice: \t"); scanf("%d",&o); printf("Enter two numbers: \t"); scanf("%d %d",&n1,&n2); switch (o) { case 1: a=n1+n2; printf("\n Please wait.."); sleep(1); printf("\n Answer is %d",a); printf("\n Perform another action too? 1 for Yes and 0 for No \t",c); scanf("%d",&c); if (c==1) { goto S; } if (c==0) { printf("\n \n \n Bye!"); } else { printf("Choice ain't correct!"); } L: printf("\n \n Restart loop? 1 for Yes and any other number for No \t",r); scanf("%d",&r); if (r==1) { printf("\n \n Restarting Loop.."); sleep(1); goto S; } else { printf("\n \t \t \t Bye!"); goto L; } break; case 2: a=n1-n2; printf("\n Please wait.."); sleep(1); printf("\n Answer is %d",a); printf("\n Perform another action too? 1 for Yes and 0 for No \t",c); scanf("%d",&c); if (c==1) { goto S; } if (c==0) { printf("\n \n \n Bye!"); } else { printf("Choice ain't correct!"); } M: printf("\n \n Restart loop? 1 for Yes and any other number for No \t",r); scanf("%d",&r); if (r==1) { printf("\n \n Restarting Loop.."); sleep(1); goto S; } else { printf("\n \t \t \t Bye!"); goto M; } break; case 3: a=n1*n2; printf("\n Please wait.."); sleep(1); printf("\n Answer is %d",a); printf("\n Perform another action too? 1 for Yes and 0 for No \t",c); scanf("%d",&c); if (c==1) { goto S; } if (c==0) { printf("\n \n \n Bye!"); } else { printf("Choice ain't correct!"); } N: printf("\n \n Restart loop? 1 for Yes and any other number for No \t",r); scanf("%d",&r); if (r==1) { printf("\n \n Restarting Loop.."); sleep(1); goto S; } else { printf("\n \t \t \t Bye!"); goto N; } break; case 4: a=n1/n2; printf("\n Please wait.."); sleep(1); printf("\n Answer is %d",a); printf("\n Perform another action too? 1 for Yes and 0 for No \t",c); scanf("%d",&c); if (c==1) { goto S; } if (c==0) { printf("\n \n \n Bye!"); } else { printf("Choice ain't correct!"); } O: printf("\n \n Restart loop? 1 for Yes and any other number for No \t",r); scanf("%d",&r); if (r==1) { printf("\n \n Restarting Loop.."); sleep(1); goto S; } else { printf("\n \t \t \t Bye!"); goto O; break; default: printf("Choice ain't correct"); break; } } }
source share