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;
  • Наука та технологія

КОМЕНТАРІ • 61

  • @BroCodez
    @BroCodez  2 роки тому +54

    #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;
    }

  • @prumchhangsreng979
    @prumchhangsreng979 2 роки тому +22

    I like that we have to do exercise as we learn, instead of just learning the theory and how it work.

  • @Mini_CS
    @Mini_CS 2 роки тому +16

    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!

    • @Mini_CS
      @Mini_CS 9 місяців тому

      @@aradhya1065 👍

  • @esFjord
    @esFjord 9 місяців тому +5

    Quick, simple & clear example. Thank's a ton!!

  • @codingprograms2078
    @codingprograms2078 6 місяців тому +1

    The coldest explanation 🥶 savage

  • @MrAlexanderFriedrichder13te
    @MrAlexanderFriedrichder13te Рік тому +1

    Nice video! I have a test next week about case . Nice explanation

  • @muffledd
    @muffledd 9 місяців тому

    thanks! love u bro 🙏🏻

  • @crazygur1y
    @crazygur1y 12 днів тому

    You are saving my life here bro

  • @sevanthishekar4379
    @sevanthishekar4379 4 місяці тому

    Thank You For This!

  • @akai2922
    @akai2922 Місяць тому +1

    bro u got my back allways

  • @ThaMentalGod2003
    @ThaMentalGod2003 6 місяців тому

    thanks for uploading 😎quick and to the point. as it should be.
    peace, stay chillin

  • @Hard_facts101
    @Hard_facts101 4 місяці тому

    Thank you so much appreciate bro

  • @user-zu3zk9lw1q
    @user-zu3zk9lw1q Рік тому

    Very helpful data thanks bro

  • @user-vn2vd7hg7w
    @user-vn2vd7hg7w Місяць тому

    Love you bruhw

  • @gamingcomputers7485
    @gamingcomputers7485 6 місяців тому

    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

  • @mohamedbadre434
    @mohamedbadre434 Рік тому

    Great, thank you

  • @SurajDas-zi7wb
    @SurajDas-zi7wb 2 роки тому +1

    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-

  • @ghazihattab
    @ghazihattab 2 роки тому

    UR THE BEST

  • @svenvanbeekveld1149
    @svenvanbeekveld1149 2 роки тому

    Bruh nice vid on the Switch-case explanation

  • @andrewfross6713
    @andrewfross6713 11 місяців тому +2

    Great Video.
    How do you get C program to run in vscode?

  • @NezarAhmed57
    @NezarAhmed57 8 місяців тому

    Thxn bro!

  • @s.a.g.6571
    @s.a.g.6571 9 місяців тому

    Which software u use for c programming

  • @bustin9938
    @bustin9938 3 місяці тому

    1 more happy customer thank you

  • @kevinwesah2819
    @kevinwesah2819 2 роки тому +10

    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

    • @rishinayyar4018
      @rishinayyar4018 2 роки тому +5

      no you really dont have to learn java or c++ for cyber security but the rest you mentioned is just enough

  • @naveenkumar1853
    @naveenkumar1853 7 місяців тому

    Good

  • @ALKOOOL
    @ALKOOOL Рік тому

    thx bro

  • @sedoxly9633
    @sedoxly9633 6 місяців тому

    That's Why He's The GOAT THHHHHEEEEEEE GOOOOOOAAAAAAAAAAAAAT🔥🔥🔥🔥🔥🔥

  • @gambitjr8197
    @gambitjr8197 2 роки тому +11

    Thanx "bro" you're making my C Programming module easy.

  • @perichappanlakshmanan7849
    @perichappanlakshmanan7849 7 місяців тому

    When should we use if else when should we use switch...?

  • @Tuper4
    @Tuper4 4 місяці тому

    Is there any Switch-Case function in python? Thanks for your videos!

  • @redvex5998
    @redvex5998 8 місяців тому

    Can i use numbers or It use only words?

  • @user-ace96plays
    @user-ace96plays Місяць тому +1

    DONE❤

  • @ryanalnaser914
    @ryanalnaser914 2 роки тому +1

    whatever anything before or after or anything I do or did or anything

  • @TheScissorunner
    @TheScissorunner Рік тому +2

    Tried to use a float or double for my variable...failed, can't use float with switch.
    Tried to use operators

    • @keanusabine6335
      @keanusabine6335 Рік тому +1

      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?

  • @HyProDuxyMusicHandle
    @HyProDuxyMusicHandle 11 місяців тому +1

    gonna dm this vid to yendre dev rq

  • @faaalmax7965
    @faaalmax7965 Рік тому

    Really a Chad!

  • @user-kp4qk4cf1n
    @user-kp4qk4cf1n 2 місяці тому

    Who is this genius yeeaah dude you need an "A"

  • @modnar246
    @modnar246 2 роки тому

    just having comment so there are many prayers

  • @grimward1448
    @grimward1448 2 роки тому +2

    when i type "Ahsfasfka" it prints Case 'A' cuz it starts with A. How can i prevent that one ?

    • @oways8080
      @oways8080 2 дні тому

      u have to use string

  • @madosenkohl
    @madosenkohl 9 місяців тому

    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)?

    • @michaelucho
      @michaelucho 5 місяців тому

      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.

  • @mirzaammar3815
    @mirzaammar3815 6 місяців тому +1

    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?

    • @talkingdownonnett
      @talkingdownonnett 6 місяців тому

      How else do you plan on writing outcomes? It’s not a shortcut it’s a more efficient and effective way to write.

    • @michaelucho
      @michaelucho 5 місяців тому

      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.

  • @user-mc9uv7ij7x
    @user-mc9uv7ij7x Рік тому

    ❤❤❤❤❤❤

  • @avdhoot3749
    @avdhoot3749 10 місяців тому

  • @panashejonga4258
    @panashejonga4258 9 місяців тому

    tatenda bro

  • @s.a.g.6571
    @s.a.g.6571 9 місяців тому

    Bro which compiler do u use

    • @JayGMac
      @JayGMac 9 місяців тому

      He is using Microsoft Visual Studio

  • @honza572
    @honza572 2 роки тому

    isn't E also a grade?😅

  • @woodenmonkeyfox
    @woodenmonkeyfox Рік тому +1

    Nice ! Thanks for the tutorial 👍
    But there is not E ?
    I didn't had the same grade system ¯\_(ツ)_/¯

    • @michaelucho
      @michaelucho 5 місяців тому

      You can always put it in your code 😃. Where I grew up we also used "S" for "Satisfactory".

    • @woodenmonkeyfox
      @woodenmonkeyfox 5 місяців тому

      @@michaelucho like the game ? 😂

  • @Grab-Deals
    @Grab-Deals 3 місяці тому

    Hi

  • @PSIwolf39
    @PSIwolf39 7 місяців тому

    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.");
    }
    }

  • @seif7653
    @seif7653 Рік тому

    Bro

  • @tomchristensen3121
    @tomchristensen3121 9 місяців тому

    random