C Programming Tutorial 8, If Statement Pt.3

About character now in this tutorial we’re going to expand on that idea let’s say we want to make it so if the user enters a capital a they get hello if they enter a capital B they get happy birthday and if they enter a capital C they’ll get welcome well what we can do to do that is we.
Can just put else if my car double equals a capital B then we want it.

Happy birthday so I’m say happy birthday and then end the line with a /n alright so now basically what this is going to do right here is this going to say if the character that the user enters is equal to.

A capital A then it’s gonna print out hello but if it doesn’t equal a capital A it’s gonna come down here and check and see if it’s equal to a capital B if it’s equal to a capital B then it’s gonna print out happy birthday if it’s not equal to a capital B then it’s gonna.
Go down here and print out you entered an invalid character all.

Right so now let’s just go ahead and run this program and see if this works right here so I’m going to say please enter a character winter will enter capital A we see we get hello and we enter a capital B and we get happy birthday spelled wrong all right and if we enter in any other character besides a or B we should get you entered an invalid character all right so now let’s just do this for a capital C so we’re going.

To say else if my car double equals a capital C then we’re just going to print.

Out welcome all right so let’s say welcome and then end the line all right so now let’s just go ahead and run this now if we enter a capital C we get welcome and if we.

And enter anything besides a capital A a capital B in a capital C we should get you entered an invalid character yep you entered an invalid character now.

Let’s say we wanted to make it so if the user enters an a a B or a C.

They’ll get hello well one way of doing this is just changing all these down here.

– hello so we can just change this to hello and this – hello right here so now if the user enters an A it’ll print out hello if these are enters a B it’ll print out hello and if these are enters a C it’ll print out hello otherwise.

They’ll just print out you entered.

An invalid character so we just.

Enter a we get hello we enter B we get hello and if we under C we should get hello as well yep all right but there is.

Actually a much easier way of doing this what we can actually do right.

Here is we can say if my car double equals a and then we can do these two vertical bars and these two vertical bars are basically the same thing as or so we’re saying.

If my car equals a or my car equals B or my car equals C then we want to print out hello all right all right so now let’s just go ahead and run this and make sure that it works so.

Once again when it’s going to do is going to say if my character equals a or if my.

Or if my character equals C then we’re just going to print out hello so let’s just go ahead and run this please enter a character or a wheel after a we get hello we enter B we get hello we enter C and get hello and if we enter any character besides capital a capital B or capital C we should get you entered an invalid character yep perfect all right.