C Programming Tutorial – 23 – Shorthand if else

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






33 responses to “C Programming Tutorial – 23 – Shorthand if else”

  1. Ajay Bhosale Avatar

    why it is not working with (friends=1)? "" : "s" this…?

  2. Maloucaze Avatar

    make it 30, you never know when a german is going to use your program

  3. Caput Avatar

    My code is exactly like yours and I always get the same team. If lastName starts with a 'N' or an 'R' i always get Red team. Pls help.
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>

    int main(){

    char lastName[20];

    printf("Enter your last name: n");
    scanf(" %s", lastName);

    (lastName[0] < 'M') ? printf("Blue Teamn") : printf("Red Teamn");

    return 0;

  4. DerSohnDesAlvaters Avatar

    I don't get it. No matter what I type I still keep getting red team.

  5. waris kn Avatar

    Can we use the statement without printf method. I have done a program but it seems that the output is showing only when I use printf function only.
    Program is defined below
    Int main
    Int i=0;
    Printf("enter name:");
    Scanf("%s",& Name);
    (Name[0]='a')?i==5:i==3;//here by using ptrintf the output is obtained,but cannot assign a value 🙁 //

    The problem is the the value for I have assigned is not printing the output,i must be 5 or 3 but it is showing 0 itself the value I have assigned before.please anyone in this universe help me,bucky are you out there.

  6. Danny ko Avatar

    god bless Bucky Roberts!!!!

  7. thegaming lime Avatar

    Never mind I figured it out

  8. thegaming lime Avatar

    This code is not working, the headers are there as well, just didn't copy them

    int main()
    char lastName[20];
    printf("Enter your last name: n");
    scanf(" %s", lastName);

    (lastName(0) < 'M') ? printf("Blue Team") : printf("Red Team") ;

    return 0;

  9. elektrikpulse61 Avatar

    Anyone hear him say that his last name "Roberts" is above "M"? No, just me?

  10. Djamel Arab Avatar

    it doesnet work with me !!

    int main()
    int age;
    printf("how old are you ?:n");
    scanf(" %d" ,age);
    (age>=18) ? printf("you can enter") : printf("you can not enter");


    even if write the programme like the usual way it doesn't work !!!


    int main()
    int numbers;
    printf("enter your number here:n");
    scanf(" %d", numbers);
    if(numbers <= 11){
    printf("you are in the first team");
    printf("you are in the reserve team");

    the programme work just like u write it !

  11. nikola 011 Avatar

    can any1 explain me why is he using string for just one letter (s)? why he didnt use char (%c)?

  12. guoitdreuy Avatar

    How come this doesn't work if you use %c for a character rather than %s for a string? Since we are only trying add a single character s….

  13. SpydreX Official Avatar

    #include <stdio.h>

    int main()
    int friends;
    printf("List how many friends you have!n");

    printf("I have %d friend%s n", friends, (friends!=1) ? "s" : "");

    return 0;


  14. Mauricio Dávalos Avatar

    Here's my code: I'd appreciate positive suggestions to optimize or improve my code , thanks

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    int main()
    int i, dice, tot1=0, tot2=0;
    char hit, answer;

    for(i=1; i<=3; i++){
    printf("Press h to hit the dicen");
    scanf(" %c", &hit);
    if(hit == 'h'){
    dice = ( rand()%6 ) + 1;
    tot1 += dice;
    printf("ndice %d: %dnn", i, dice);
    printf("nnTotal: %d", tot1);
    printf("nnNext roll is gonna be higher, lower or same (hls): ");
    scanf(" %c", &answer);

    for(i=1; i<=3; i++){
    printf("nnPress h to hit the dicen");
    scanf(" %c", &hit);
    if(hit == 'h'){
    dice = ( rand()%6 ) + 1;
    tot2 += dice;
    printf("ndice %d: %dnn", i, dice);
    printf("nnTotal: %d", tot2);

    if(answer=='h')(tot2>tot1)? printf("nYou won"): printf("nYou lost");
    if(answer=='s')(tot2==tot1)? printf("nYou won"): printf("nYou lost");
    if(answer=='l')(tot2<tot1)? printf("nYou won"): printf("nYou lost");

  15. EllixV Avatar

    your teaching/ explanation has gotten better in this video

  16. Engr AttaurRehman Hashmi Avatar

    can we use two tests in short-if-else statements?

  17. Rohit_Veer Avatar

    Bucky you re awesome Bro

    I have Use Two Shorthand if else in a single Printf statement and Made this

    #include <stdio.h>
    #include <stdlib.h>

    int main(){
    int friends;
    char name[6];

    printf("What is Your Name? n");
    scanf(" %s", name);
    printf("How Many Friends Do you Have? n");
    scanf(" %d", &friends);
    printf("%s has %s %d Friend%s ", name, ((friends!=1) ? "" : "Only"),friends, ((friends!=1) ? "s" : ""));
    return 0; }

  18. Kaizen Avatar

    Brilliant, these are so useful.

  19. Cristina Polonia Avatar

    Can I ask How do I make sure people use numbers only and not characters (or vice versa?). thanks

  20. AJay Gupta Avatar

    what if user has to enter the number of friends. anyone help plz

  21. Nicu Drosu Avatar

    This is amazing, thank you so much for these.

  22. Karan Gupta Avatar

    the part
    (friends!=1) ? "s" : " ";
    don't we have to write print with s like printf"s"

  23. Michael Moore Avatar

    I always wondered what the ? : meant in code. Thanks. Love your videos.

  24. Michael Moore Avatar

    what about lowercase versus uppercase when it comes to the value of letters? is b greater than or less than A?

  25. le00 Avatar

    love ur videos

  26. Murad Babayev Avatar

    6:41 why did the "friend" term turned blue? Is friend a valid statement in c?? ))

  27. babu y Avatar

    i am executed 23rd tutorial program, but i am getting only "red team" as output,,,,………….

  28. Peterolen Avatar

    As others have pointed out English is pretty easy compared to many other languages. If I was to write something like this in Swedish I could not simply write code that handles all words the same because the plural ending can vary much more from word to word.

    en: cat, cats
    sv: katt, katter

    en: glove, gloves
    sv: vante, vantar

    en: locker, lockers
    sv: skåp skåpen

    To use a definite articles in English you just add "the", but in Swedish it's not as easy as that.

    en: the cat, the cats
    sv: katten, katterna

    en: the glove, the gloves
    sv: vanten, vantarna

    en: the locker, the lockers
    sv: skåpet, skåpena

  29. Akalion Avatar

    7:04 Oh boy, if you think English is confusing with that shit try Russian.

  30. alonza thompson Avatar

    Thanks for the vids…really appreciate this

  31. ZURATAMA1324 Avatar

    Question, could I add a regular if-else statement in printf?

Leave a Reply

Your email address will not be published. Required fields are marked *