C Programming Tutorial – 19 – 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

Comments

Octopushorse says:

Excuse me. There is no option for me. I sexually identify as an attack helicopter.

IndiCoder says:

Brackets will come handy. TIP

shiretsu says:

bucky’s gender binary bonanza

Borislav Gridnev says:

My 7+ age doesn’t work.

Lester Cute says:

My code is not running the first printf statement whenever i type Lester.
#include
#include

int main()
{

char name[20];

printf(“Who are you?n”);
scanf(” %c”, &name);

if (name == ‘Lester’){
printf(“Sorry, Lester you can’t use this name.n”);
}else{
printf(“What are you looking for?n”);
}

return 0;
}

lathiya Dhruvraj says:

hello  sir,   I have written this simple  code  , while executing this code I have to enter one more key or enter one more variable on output screen  to get my  answer (also answer is always correct) but I don’t understand why I have to press that one more key to get my final answer. I google it but I cant found any thing so finally decided to comment this.Hope you will help me. plz mail me – lathiyadhruvraj44@gmail.comor  anyone reading this comment and you know what the problem is , plz  plz  help me..
#include int main()
{
    int a,b,c,aot;
    printf(“enter the three angles of a triangle”);
    scanf(“%d %d %d “,&a,&b,&c);    aot=a+b+c;    if(aot==180)
        printf(“angles of triangle are valid”);
    else
        printf(“angles are not valid);       }

Hambo007 KoD says:

3:30 Triggered !!!!!!!!!!
;p

Caio Costa says:

I’d add the gender question inside the first “if” brackets, so if ur under 18 it isn’t even asked

int age;
char gender;

printf(“Whats ur age?n”);
scanf(” %d”, &age);

if (age >= 18){

printf(“Whats ur gender? (m/f)n”);
scanf(” %c”, &gender);

if (gender == ‘m’){
printf(“You may enter this website, dude!n”);
}
if (gender == ‘f’){
printf(“You may enter this website, girl!n”);
}
}else{
printf(“Nothing to see here.n”);
}

Rohit Bhandwalkar says:

#include
#include

int main()
{
int age;
char gender;

printf(“how old are you?n”);
scanf(” %d”, &age);

printf(“what is your gender?(m/f)n”);
scanf(” %c”, &gender);

if(age>=18)
{
printf(“you may enter this website”);
}
if(gender==’m’)
{
printf(“dude”);
}
else
{
printf(“m’lady”);
}
else
{
printf(“nothing to see here!);

}
return 0;
}

this program cannot run properly, it shows error…

Yaman Yadav says:

code blocks is crashing when i run these codes.

yerrapotu kiran says:

Thank you bucky

Mahmod Jabareen says:

your tutorial is great and very helpful

but please don’t say basecly like one million times

Mr Green says:

ow that is good! cool !

Blake Ortiz says:

This video would trigger so many people if it came out in 2017 and the idiots who think non-binary, etc. is really a thing saw it.

Kenneth Winston says:

Hey bro u helped me out a LOT

Scantanious Combustion says:

For those who are interested I thought putting the code where it asks for your gender inside the if statement, because it’s redundant to ask for your gender if you’re underage anyway. Like this:

int main()
{
int age;
char gender;

printf(“How old are you?n”);
scanf(” %d”,&age);

if(age >= 18){
printf(“What is your gender? (m/f) n”);
scanf(” %c”,&gender);

printf(“nYou may enter this website “);

if(gender == ‘m’){
printf(“dude!”);
}else{
printf(“m’lady”);
}

}else{
printf(“Nothing to see here!n”);
}

return 0;
}

pranjali GHODE says:

is it important to give( after the statement completes

Leandro170 says:

if(gender == ‘m’)
{printf(“dude n”);}
else{printf(“m’lady”);}
Oh god,feminism/machism(god idk how 2 write that) on coding

Hà Chí Hào says:

what is wrong here, help me 🙁

int age;
int gender;

printf(“How old are you ?n”);
scanf(“%d”, &age);

printf(“What is your gender ?n”);
scanf(“%s”, gender);

if(age >= 18){
if(gender == ‘male’){
printf(“You are a man”);
}

if(gender == ‘female’){
printf(“You are a woman”);
}
}else{
printf(“You are a kid”);
}

return 0;

Christian Khoueiri says:

You can also move your gender print statement to the inside of the brackets of your if(age>18).
if(age>=18)
{
printf(“What is your gender? (m/f) n”);
scanf(” %c”, &gender);

printf(“nYou may enter”);

if(gender==’m’)
printf(“, dude!”);

else
printf(“, ma’lady!”);
}

That way we won’t have to ask the gender of users under 18.

Ahmad says:

@thenewboston how are u recording ur videos, what program are u using?

ヤクザYakuza says:

hi can someone rewrite the code in the replys ?”sorry for my england”

ohh wee says:

int main (){

int age;
char name[10];
char nameLast[10];
char gender;

printf(“Enter your first name and last name pls:”);
scanf(” %s %s” ,name ,nameLast);

printf(“%s %s pls enter your age :” ,name ,nameLast);
scanf(” %d” ,&age);

printf(“%s %s pls enter your gender (M/F) :” ,name ,nameLast);
scanf(” %c” ,&gender);

if(age >= 18 && gender == ‘M’)
{
printf(“Welcome %s my DUDE!!!” ,name);
}
else if(age >= 18 && gender == ‘F’)
{
printf(“Welcome %s M’lady” ,name);
}

else
{
printf(“UH OH YOU CANNOT ENTER!!!”);
}

return 0;
}
i made this code

felix john says:

R u dumbfuck or what ,make the screen enlarge

Karanvir Sandhu says:

#include
#include

int main()
{
int itemssold;
char daysnosale;

printf(“How many items were sold today ?n”);
scanf(” %d”, &itemssold);

printf(“Did we had any sale today ? (y/n)n”);
scanf(” %c”, &daysnosale);

if ((itemssold>=10) && (daysnosale==’y’)) {printf(“We had a great day for sales !”);}
else {printf(“We are in loss !”);}
return 0;

}

Leverquin says:

but even if you don’t trype f for female, and use like: s that will be “else” too cuz you didn’t make char f anywhere O.o right?

Beza says:

Whats wrong with this code? I made a simple calculator for 4 operations and when i press anything except 4 it goes to multiplication and doesnt multiply the numbers or the operation it was meant to do:

#include
#include

int main(){
system (“color 0B”);
float a,b,numberforoperation;
float sum=a+b;
float sub=a-b;
float div=a/b;
float mul=a*b;
printf(“Simple calculator with two numbers.”);
printf(” n n n 1-Additionn 2-Subtractionn 3-Multiplicationn 4-Division n”);
scanf(” %d”,&numberforoperation);
if(numberforoperation==’1′){
printf(“Enter two numbers you want to add togethern”);
scanf(” %f”,&a);
scanf(” %f”,&b);
printf(“Result: %f”,sum);

}else if(numberforoperation==’2′){
printf(“Enter two numbers you want to subtract n”);
scanf(” %f”,&a);
scanf(” %f”,&b);
printf(“Result: %f”,sub);

}else if(numberforoperation==’3′){
printf(“Enter two numbers you want to divide n”);
scanf(” %f”,&a);
scanf(” %f”,&b);
printf(“Result: %f”,div);

}else{
printf(“Enter two numbers you want to multiply n”);
scanf(” %f”,&a);
scanf(” %f”,&b);
printf(“Result: %f”,mul);

}

return 0;
}

pravardh cv says:

#include
#include

int main()
{

int age;
char gender;

printf(“Enter your agen”);
scanf(“%d”,&age);

printf(“Enter your gender (‘m/f’)n”);
scanf(“%c”,&gender);

if(age >=18){
printf(“You have been authorized!”);
if(gender==’m’){
printf(“Welcome sir!n”);
}else{
printf(“Welcome ma’amn”);
}
}else{
printf(“You are not old enough to enter this websiten”);
}
return 0;
}

plz tell me what is wrong

Brandon says:

PLEASE HELP!! i keep getting (Warning: comparison between pointer and integer [enabled by default]) It does not allow me to give imput
int main()
{
    char gender[15];
    printf(“please enter your sex(m/f):”);
    scanf(” %c”, gender);
    if(gender == ‘m’){
        printf(“hi dude”);
    }else{
       printf(“hi mam”);
    }
    return 0;
}

Alex Schulte says:

You could literally type in any character for the gender and it would output “m’lady” if >= 18, right?

Petar Mioč says:

great video!

Kabelo Moleme says:

i love you, dude you taught me a lot

Arijit das sharma says:

can anybody help me this code is not asking my name
 #include
#include

int main()
{
char name[20];
int age;
char sex;
printf(“whats ur name? n”);
scanf(“%s” ,name );
printf(“How old are you?n”);
scanf(” %d”,&age);
printf(“whats your gender?? (m/f) n”);
scanf(” %c” & sex);
if(age >= 18){
printf(“%s can enter this websitet “,name );

if(sex=’m’){
printf(“dude “);

}else{
printf(“m’girl”);

}

}else{
printf(“%s cant enter this website n”, name);
}

return 0;

The FUTURE Co. says:

Thanks for the tutorial. I would like to ask, the gender question is nested inside the equal or above 18 condition, if the condition is below 18, why the sequence has to go to ask the gender? It didn’t happen when I coded in Pascal.

Dee Dee says:

Videos are helpful but I think font size should be little larger for a better view.

Wesley Richardson says:

what does %c mean and how does it work?

vova zhyhanov says:

I Love you,  dude!
The way you teaching us is nothing but a smooth ride along C language.
This is the funniest way of representing C basics I`ve ever seen!:)
P.S. and also easy to understand, highly recommend, people!!

Esdras Katumuako says:

are you assuming genders

Youval K says:

if itsn’t a male it doesn’t mean that’s a female it could be a transexual

Ahmad says:

Can anyone tell me, how is he recording his videos?

Dr. Pigeon says:

I haven’t seen more than 15 vids of the same channel before. You are helping me to accomplish my dream
btw i’m 15

Omega says:

Are you saying that there are only 2 gender?

Now, someone will triggered.

John Zoidberg says:

Is it really necessary to put the else statement on the same line as the closing }curly bracket?

Jose Jerry Aiden says:

/ newboston,you are great…thank you for your tutorial
#include
#include
void main()
{
int a,b;
b=3;
clrscr();
printf(“if you like this channel type ‘3’ if not, type any no : n”,a);
scanf(” %d”,&a);
if(a==b)
{
printf(“I love this channel it is awesome for a noob like me”);
}
if(a!=b)
{
printf( “I hate thenewboston “);
}
getch();
}

JRad says:

I think the way you lay out your code is messy.
The way I have been taught for C#, the { is under the if, do or for functions and else is under the line of } instead of being on it.

Kelly Freet says:

Excuse me Bucky, but there are more than two genders, it is no longer a binary choice. Sex is different than gender. I identify as a cat that likes bagels, so you would have to include that in an else if if you were to use the word ‘gender’. 😉

shizyninjarocks says:

Well explained.

 Write a comment

*

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

Please click below to support us on Facebook!