+ 1
Can i use if-else statement in a program of switch case statement before switch (ch) as shown in my code.
8 Antworten
+ 8
If you want to evaluate something before entering the switch statement, then yes you can.
+ 10
if (ch==1||ch==2||ch==3) { //check this out
printf ("Enter the side\n");
scanf("%d",&s);
printf ("side = %d\n",s);
} else {
printf ("Enter the length and breadth");
scanf ("%d%d",&l,&b);
printf ("length = %d\n",l);
printf ("breadth = %d\n",b);
}
+ 5
What's the condition in the if-else statement?
+ 3
No problem. Happy coding!
+ 1
It works 👍
Thank you ☺
0
but it doesn't work when I tried it in my Q5 code.It always gives the output of case 1 only.
0
these are the if else conditions in the previous code if I don't want to repeat these conditions in the cases as i have done in my Q 5 code