+ 1

Can i use if-else statement in a program of switch case statement before switch (ch) as shown in my code.

https://code.sololearn.com/cicDcBGdkebE/?ref=app

20th Dec 2018, 7:44 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
8 Réponses
+ 8
If you want to evaluate something before entering the switch statement, then yes you can.
20th Dec 2018, 8:23 AM
Lambda_Driver
Lambda_Driver - avatar
+ 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); }
20th Dec 2018, 10:25 AM
Lambda_Driver
Lambda_Driver - avatar
+ 5
What's the condition in the if-else statement?
20th Dec 2018, 9:04 AM
Lambda_Driver
Lambda_Driver - avatar
+ 3
No problem. Happy coding!
20th Dec 2018, 11:18 AM
Lambda_Driver
Lambda_Driver - avatar
+ 1
It works 👍 Thank you ☺
20th Dec 2018, 10:36 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
0
but it doesn't work when I tried it in my Q5 code.It always gives the output of case 1 only.
20th Dec 2018, 8:51 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
20th Dec 2018, 9:28 AM
Titiksha Tyagi
Titiksha Tyagi - avatar
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
20th Dec 2018, 9:29 AM
Titiksha Tyagi
Titiksha Tyagi - avatar