An overview of how to use switch statements in C! Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!
Kevin thanks for great video; I think a lot of people might skip over covering switch statements but as shown; by using fall through logic they can be very useful. I wrote the code out and included a default: section to keep track of consonants ie. ++consonants; that is presuming the random string only contains letters.
Cool, that's a good example of using default. And I think switches are good to use as long as everyone editing the code is onboard with them and appreciates how they work, I've definitely noticed some folks either don't bother with them or are generally against using them. I'm glad you enjoyed the video Peter! :-)
here is an easier example #include int main() { int day; printf("Enter a day of the week (1-7): "); scanf("%d", &day); switch(day) { case 1: printf("Sunday "); break; case 2: printf("Monday "); break; case 3: printf("Tuesday "); break; case 4: printf("Wednesday "); break; case 5: printf("Thursday "); break; case 6: printf("Friday "); break; case 7: printf("Saturday "); break; default: printf("Invalid input "); break; } return 0; }
Video about switch statement, but I learned a lot of cool things. Thank you, Sir!
Kevin thanks for great video; I think a lot of people might skip over covering switch statements but as shown; by using fall through logic they can be very useful. I wrote the code out and included a default: section to keep track of consonants ie. ++consonants; that is presuming the random string only contains letters.
Cool, that's a good example of using default. And I think switches are good to use as long as everyone editing the code is onboard with them and appreciates how they work, I've definitely noticed some folks either don't bother with them or are generally against using them. I'm glad you enjoyed the video Peter! :-)
STEP BY STEP TUTORIAL FOR LEARNERS.I appreciate your contribution.
I’m glad you enjoyed it! :-)
The explanation was really good.
I’m glad that you enjoyed it Rezuwan! :-)
One of the Best Explainers!
exactly what I was looking for!
Awesome, I’m glad it was helpful for you Stanley! :-)
thank you so much
You're very welcome! :-)
here is an easier example
#include
int main() {
int day;
printf("Enter a day of the week (1-7): ");
scanf("%d", &day);
switch(day) {
case 1:
printf("Sunday
");
break;
case 2:
printf("Monday
");
break;
case 3:
printf("Tuesday
");
break;
case 4:
printf("Wednesday
");
break;
case 5:
printf("Thursday
");
break;
case 6:
printf("Friday
");
break;
case 7:
printf("Saturday
");
break;
default:
printf("Invalid input
");
break;
}
return 0;
}
We go over an easier example first at the start of the video! :-)