# C Programming Tutorial For Beginners

Like print out a little error message we’re just gonna say else and basically the code inside this.

Else block will get executed if none of these conditions up here true and down here we can just make a print F and I’m just gonna print out invalid operator so now we have our if statement or if block setup and this should be everything that we need to use our little calculator alright so let’s go ahead and run this program so you can see over here it says enter a number so we can enter a number.

Let’s enter in five point nine and enter an operator we’ll add numbers and now let’s enter in 4.0 so we’re gonna add five point nine and four so when I click enter we should go through all of those if statements and figure out what we need to.

Do and you’ll see over here that we’re adding five point nine and four together and we’re getting nine point nine so looks like the program worked let’s try it again we’ll try another operator.

Why don’t we try to multiply some numbers so let’s multiply six and times I don’t know five point seven so we get thirty four point two that seems about right all right and then one more time we’ll run this and I want to try to enter in an invalid operator so we’ll say.7 and I’m just gonna enter in a G so that’s an invalid operator that’s not going to work.

And I’ll enter my number let’s do 8 and you can see it tells us invalid operator so basically we have a four function.

Calculator this calculator can multiply divide subtract and add and if you.

In a correct operator it’s smart enough to yell at you and tell you that you have an invalid operator so this seems to work pretty well I’m pretty happy with it and you can see down here like this is a perfect situation for using something like an.

If statement right we have this variable opie right it’s storing some sort of operator.

We don’t necessarily know what’s inside of there but I can use.

If statements and I can respond to the different scenarios so in the situation where it’s a.

Plus sign I can respond in the situation where it’s a minus sign I can respond etc and this just makes our programs a lot smarter and it helps us to do different things when different situations arise in this tutorial I want to talk to you guys about using switch statements in C now a switch statement is basically a special type of if statement which will allow us to compare one value to.

A bunch of different values and it’s essentially doing the same thing as an if statement it’s allowing us to check different conditions and if different conditions are true then we can do certain things but a switch statement makes.

It really really easy for us to compare one specific value to a bunch of other values now I’m gonna show you guys how we can use that in this tutorial to make a little test app so I’m gonna build a.

Little program that will take a letter grade and depending on the letter grade it will tell you whether or not you did good or bad on a test so if you got an a on the test it would say hey.

You did a good job if you got a B on its house it’d be like hey you did alright.