Learn Programming Technique C to Master Skills - If .... else if Statement Program

  • last week
Transcript
00:00Hello everyone. This is Sandeep. In my previous video, I have explained about two-way selection
00:12and I have explained the program in a flowchart. So this was the program that if the purchasing
00:18amount is greater than equals to 10,000, then 10% discount. If the purchasing amount is
00:24greater than equals to 5,000, the customer is going to get 5% discount. If the purchasing
00:30amount is less than 5,000, then no discount. But this time we have to take decision for
00:36the two times. Okay. And then we have to calculate the discount and the net amount in which the
00:43customer purchased the goods. Okay. So I have explained the flowchart, this program, and
00:51now I'm going to implement NC. Let me open the code blocks and a new file. I'm going
01:02to make the program. I will save it. Okay. Now I will write what hash include, stdio.h.
01:27I will use what int main and inside it I use what float, p for the purchase, t for
01:36the discount, and n, the amount in which the customer purchased the goods. I will use a
01:44message here that what I am going to do is to input the purchase of goods. Okay. So I've
01:56given a message here and I will use a scanf. So what percent f for the type specifier,
02:08comma, and p. So the value is going to store inside p for the purchase. Now according to
02:17the question, if purchase, purchasing amount is greater than equals to 10,000. Okay. So
02:25according to the question, the discount will be d equals to p into 10 upon 100. Okay. So
02:33discount is going to calculate and to calculate the net amount, I will write down n equals to
02:40p minus d. Okay. So I've calculated the discount and the net amount. After that,
02:48printf slash n, discount is percent d and it is inside where d. Okay. I have to use the
03:02specifier percent f. I will use what percent f and it's going to display. Okay. So I will
03:17use the semicolon at the end and what printf slash n, net amount is, that is what percent f,
03:30then comma, dot n and what semicolon. Now if the condition will get false, I will come to
03:45what else part. Again, the condition is going to check else if, what p greater than equals to what
03:535,000. Okay. If the purchasing amount is greater than equals to 5,000, in that case, as the
04:01question says, let us see that if the purchasing amount is greater than equals to 5,000 and how
04:10much? 5%. So the purchasing amount is between 5,000 and 10,000. Okay. So in that case,
04:18d equals to p into 5 upon 100 and to calculate the net amount, n equals to p minus d. Okay.
04:32And then again, I will print the, first of all, what the discount. Discount is percent f. Where
04:44it is? It is inside the d. Okay. And then what printf slash n, net amount is percent f. Where
05:00it is? It is inside n. Okay. Now here if also the condition get false, it will come to the else part
05:10and what? It's going to display what? Simply what? No discount. Okay. So I hope I have done
05:24everything right. I should write down what? Return zero, the exit status. Okay. Of the program. Now
05:36let us quickly see if there's any error or not in the program. No, I think everything is fine. Let
05:48me click on the build button. Okay. It's showing me that it's zero error and zero warning and now
05:57I'm going to run the program. When I run the program, it's asking me the purchasing amount.
06:03Suppose I input what? 50,000. Okay. So it calculated 10% discount and the net amount is what? 45,000.
06:14Okay. Let us run one more time. Now this time I'm going to input what? 8,000, the purchase of the
06:24customer. So it's calculated the 5% and the net amount in which the customer purchased, that is
06:317,600. Okay. Then I again run the program and I input what only? Suppose 1,000, in that case what?
06:44No discount. So everything is fine. There is no error. So let us understand. Suppose I input here
06:54what? 50,000. It will take the decision here, 50,000 greater than 10,000. Condition is true.
07:02So this part is going to work. Okay. It's going to calculate 10% discount and then the net amount
07:10which is going to store inside n and then it's going to display. If I again run the program and
07:17suppose inside p, I input 8,000. So 8,000 greater than 10,000, the condition is false. It's going to
07:26come here to the else part. Okay. Again the statement 8,000 greater than 5,000. Yes,
07:33condition is true. And according to the question, it's going to calculate what? 5%. And I'm going
07:40to display the discount and the net amount. If I again run the program and suppose I input the
07:49purchase amount of customer 1,000. 1,000 greater than 10,000, here the condition gets false. It
07:56will come to the else part. 1,000 greater than 5,000, here also the condition will get false.
08:04For the second if, the else is here at the down. Okay. So it will come to this else part and going
08:13to display what? No discount. Okay. So we have seen all the conditions. Now in the next video,
08:22I'm going to start multiple selection or maybe something else. Thanks for today.

Recommended