+ 1
Can anyone help me by letting me know how touse switch in c language and what are they used for
8 Answers
+ 1
You can re-read the lessons as often as you like
+ 1
Got it thank youđ
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..
0
actually I've completed my lesson 3 4 months ago
0
thanks I've learnt it now
0
you can check if I've done it properly or not
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");