C Programming Tutorial – 23 – Shorthand if else

Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts


GG says:

im confused!!! when do you use “&” for when you assign the value from scanf

char lastName[20];
    printf(“Enter your last name:n”);
    scanf(” %s”, lastName);

char answer;
    printf(“Do you like bagels? (y/n)n”);
    scanf(” %c”, &answer);

Cristina Polonia says:

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

ewwbananaagain says:

this is great!

alonza thompson says:

Thanks for the vids…really appreciate this

Mauricio Dávalos says:

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


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”);

Engr AttaurRehman Hashmi says:

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

Nicu Drosu says:

This is amazing, thank you so much for these.

Akalion says:

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

AJay Gupta says:

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

Murad Babayev says:

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

Betsy Bernard says:

Thanks Bucky :) God bless you!

DerSohnDesAlvaters says:

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


printf(“i have %d friend%s”, friends, (friends!=1) ? “s” : “” ); is wrong

printf(“i have %d friend%s”, friends, (friends>1) ? “s” : “” );  is correct

because for 0 it still prints… i have 0 friends

nikola 001 says:

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

Rossi says:

Thanks a lot Bucky for your time, the syntax is not clear, I mean what is after the test is it a ? Or a ; also between truecode and the false code is it a comma or what. Thnx for your time

Danny ko says:

god bless Bucky Roberts!!!!

isutoshi - World of Tanks says:


Adarsh Murthy says:

Hey Buckey you are amazing.

Michael Moore says:

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

SpydreX Official says:


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;


Peterolen says:

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

ZURATAMA1324 says:

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

Maloucaze says:

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

babu y says:

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

Dragonvoice1 says:

love you bucky, please more advance C tutorials  

Daniel Guzman says:

I’m taking C programming in college and I really didn’t have a background in programming! My professor is awesome but has a heavy accent! Plus he goes so freaking fast!! Your tutorials are helping me so freaking much!! Thanks for taking your time to teach us! 😉 now I feel way more comfortable in coding 😉

james brown says:

i’m here now!! lesson 23!!

Ajay Bhosale says:

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

The FUTURE Co. says:

I watched this one at least 5 times

thegaming lime says:

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

Michael Moore says:

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

Kaizen says:

Brilliant, these are so useful.

sluttyfuck19 says:

What about using the ‘x’ when its only one letter?

yerrapotu kiran says:

Thank you Bucky

Adrian says:

I’m using Xcode version of C programming to do the challenge. Apparently every time you run the programme, the rand() function will keep on generating same value. Searched internet and found the solution. That is to put srand(time(NULL)) at the start of your code (something to do with seeding.. not sure how it works). Anyone kind enough to explain it?

Write a comment


Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours