C switch statements 🔽
Вставка
- Опубліковано 31 сер 2021
- C switch tutorial example explained
#C #switch #switches
// switch = A more efficient alternative to using many "else if" statements
// allows a value to be tested for equality against many cases
char grade;
printf("
Enter a letter grade: ");
scanf("%c", &grade);
switch(grade){
case 'A':
printf("perfect!
");
break;
case 'B':
printf("You did good!
");
break;
case 'C':
printf("You did okay!
");
break;
case 'D':
printf("At least it's not an F!
");
break;
case 'F':
printf("YOU FAILED!
");
break;
default:
printf("Please enter only valid grades");
}
return 0; - Наука та технологія
#include
int main(){
// switch = A more efficient alternative to using many "else if" statements
// allows a value to be tested for equality against many cases
char grade;
printf("
Enter a letter grade: ");
scanf("%c", &grade);
switch(grade){
case 'A':
printf("perfect!
");
break;
case 'B':
printf("You did good!
");
break;
case 'C':
printf("You did okay!
");
break;
case 'D':
printf("At least it's not an F!
");
break;
case 'F':
printf("YOU FAILED!
");
break;
default:
printf("Please enter only valid grades");
}
return 0;
}
I like that we have to do exercise as we learn, instead of just learning the theory and how it work.
Thanks for the videos so far! You make learning programing so easy and less boring. I have tried to learn programing last year, but failed because I couldn't bare to watch the videos. However, once I discovered you it made me want to code and learn. You just do it so different and I just want to see keep up the great work!
@@aradhya1065 👍
Quick, simple & clear example. Thank's a ton!!
The coldest explanation 🥶 savage
Nice video! I have a test next week about case . Nice explanation
thanks! love u bro 🙏🏻
You are saving my life here bro
Thank You For This!
bro u got my back allways
thanks for uploading 😎quick and to the point. as it should be.
peace, stay chillin
Thank you so much appreciate bro
Very helpful data thanks bro
Love you bruhw
Nice this tutorials probably old at this point but i didnt know what switch statement do and if its replacing a if statements its seems much easier than if statements and less words in line of code which is nice and the way you wriye the switch is similar to function definition but different since you need to use the case i believe as if nice nice i learned something new good to know its more useful than if statements or better to write than if statements nice thanks for the short video "course" it was really helpful
Great, thank you
Hey bro
I love your tutorial
These are awesome great word 😀
A request to you to upload tutorials faster (a tutorial a day)
Please I need to learn C so bad-
UR THE BEST
Bruh nice vid on the Switch-case explanation
Great Video.
How do you get C program to run in vscode?
Thxn bro!
Which software u use for c programming
1 more happy customer thank you
you are the best....nobody even comes close....cant wait for the ALL IN ONE VIDEO for this C series. stay blessed
one question though... my ultimate goal is to get into cyber security ( you know ethical hacking and pentesting stuff) kindly advice the core languages i should first focus on . i am currently learning C then move on to python...do i need c++ and java as well?. i was planning after python i go deep into html css and javascript and php to understand how websites are built also. so i'm confused if i will need java and c++ for cyber security .advice so that i dont spend so much time learning them/ thanks
no you really dont have to learn java or c++ for cyber security but the rest you mentioned is just enough
Good
thx bro
That's Why He's The GOAT THHHHHEEEEEEE GOOOOOOAAAAAAAAAAAAAT🔥🔥🔥🔥🔥🔥
Thanx "bro" you're making my C Programming module easy.
When should we use if else when should we use switch...?
Is there any Switch-Case function in python? Thanks for your videos!
Can i use numbers or It use only words?
DONE❤
whatever anything before or after or anything I do or did or anything
Tried to use a float or double for my variable...failed, can't use float with switch.
Tried to use operators
Why do operators not work? I just recently started with C and used a switch for my calculator and it works fine. Is there a better way?
gonna dm this vid to yendre dev rq
Really a Chad!
Who is this genius yeeaah dude you need an "A"
just having comment so there are many prayers
when i type "Ahsfasfka" it prints Case 'A' cuz it starts with A. How can i prevent that one ?
u have to use string
Greetings from germany
Thing is i tried the same thing but not with a signed char but an int(a)....question why does ist not work with int(a)?
If using an Integer instead of a Character as a variable, remember to use the correct format specifier: "%d" instead of "%c". Also check for any warning or errors in your compiler. This usually can point out to where the error can be found in your code.
I got it but we're still writing almost the same no of code lines as we would using else if.....so it's not a shortcut, rather an alternative. Isn't there any shortcut?
How else do you plan on writing outcomes? It’s not a shortcut it’s a more efficient and effective way to write.
I find "switch" statements to be more readable instead of using too many "if/else" statements which can be highly "nested" and can be difficult to read especially when dealing with multiple conditional branches. Switch statements can sometimes be more efficient than long chains of "if/else" statements. Semantic Clarity is also important. As for some "magical shortcut" welcome to C programming.
❤❤❤❤❤❤
❤
tatenda bro
Bro which compiler do u use
He is using Microsoft Visual Studio
isn't E also a grade?😅
Nice ! Thanks for the tutorial 👍
But there is not E ?
I didn't had the same grade system ¯\_(ツ)_/¯
You can always put it in your code 😃. Where I grew up we also used "S" for "Satisfactory".
@@michaelucho like the game ? 😂
Hi
Here's the code I made:
#include
#include
#include
#include
int main(){
unsigned int gradePointAverage;
printf("What is your GPA? (0,1,2,3, or 4)
");
scanf("%d",&gradePointAverage);
printf("
");
switch(gradePointAverage){
case 0:
printf("You are an absolute failure.");
break;
case 1:
printf("You need to get your life together.");
break;
case 2:
printf("You can do better than that.");
break;
case 3:
printf("That's what I like to see!");
break;
case 4:
printf("LET'S GO! THAT'S CALLED PERFECTION!");
break;
default:
printf("That was not a valid GPA.");
}
}
Bro
random