Can anyone help me by letting me know how touse switch in c language and what are they used for | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone help me by letting me know how touse switch in c language and what are they used for

27th Aug 2022, 8:45 AM
Aman mishra
Aman mishra - avatar
8 Answers
+ 1
You can re-read the lessons as often as you like
27th Aug 2022, 9:01 AM
Lisa
Lisa - avatar
+ 1
Got it thank you👍
27th Aug 2022, 2:44 PM
Aman mishra
Aman mishra - avatar
0
It's explained in lesson. Do you completed lesson? If not, do it now. Otherwise, mention here what not you understand? It's an alternative better approach to if-else when you have many conditions to check.. Consider an example : days 1 to 7 are sunday to saturday. Depending upon day value, you need to take an action like display day name. How you can go? By if else : you need if( num==1) { .. } else if( num==2) { .. } .. You need 7 if blocks.. But with swich, it can be simplified as switch(num) { case 1: //do action; break; case 2: // do action ; break; ... .. } Like this you can add as many as cases in more understanding way... Hope it helps..
27th Aug 2022, 8:57 AM
Jayakrishna 🇮🇳
0
actually I've completed my lesson 3 4 months ago
27th Aug 2022, 8:58 AM
Aman mishra
Aman mishra - avatar
0
thanks I've learnt it now
27th Aug 2022, 2:36 PM
Aman mishra
Aman mishra - avatar
27th Aug 2022, 2:36 PM
Aman mishra
Aman mishra - avatar
0
you can check if I've done it properly or not
27th Aug 2022, 2:37 PM
Aman mishra
Aman mishra - avatar
0
If input is not matched with any case values : you get no output. Instead of last case , put default case like default : printf("Your rating is invalid");
27th Aug 2022, 2:42 PM
Jayakrishna 🇮🇳