Learn Programming Technique C to Master Skills - Single If Statement Program (Flow Chart)

  • 2 days ago
Transcript
00:00Hi, this Sandeep. Today I'm going to start one-way selection program. When I talk about
00:10one-way selection program, we are going to use the if statement for one time. These types
00:18of programs are of conditions in which we use conditions, in which the conditions are
00:26given and on the basis of which we take the decision and we do the work. So let us understand
00:34this program, what the program says. First of all, I'm going to explain this program
00:40in flowchart. Then I'm going to implement the program in C. So here's the program. A
00:49shopkeeper gives discount to its customer on their purchase. If the customer purchasing
00:56amount is greater than equals to 10,000, then the customer is going to get 10% commission.
01:03If the customer's purchasing amount is less than 10,000, then no discount.
01:09Okay, so the purchasing amount is greater than equals to 10,000, then 10%. If the purchasing
01:14amount is less than 10,000 of a customer, then no discount. What we have to do, we have
01:21to calculate the discount and the net amount in which customer purchase the goods. So we
01:26have to calculate two things. One is discount and also the amount in which the customer
01:34purchase the goods. That is from the actual amount, the discount is going to deduct and
01:40we are going to get the amount in which the customer purchase the goods. Okay, now whenever
01:46we read the program, the first thing which should come in our mind that how many variables
01:51should we take. So when we read the program, we understand that we have to take three variables,
02:00P for purchase, D for the discount and N for the amount in which the customer purchase
02:08the goods. Okay, now inside the decision box, we have to write down the things according
02:15to the question that if the purchasing amount is greater than equals to 10,000, then 10%
02:21is calculated and if the purchasing amount is less than 10,000, then it should display
02:25what no discount. So let us do the dry run and see how the things will work. I'm going
02:32to input the purchasing amount of the first customer. Suppose the purchasing amount of
02:39the first customer is what 25,000. It made the purchase of 25,000. It will come to the
02:48decision part. If 25,000 greater than 10,000, yes, 25,000 is greater than 10,000. It will
02:55come to the yes part. Inside P, it is what 25,000 as the question says that if customer
03:04purchase is greater than equals to 10,000, then 10% discount. So here's the formula
03:09of it to calculate the 10% discount. Inside P, it is 25,000 into 10 upon 100. So the calculation
03:18to get the discount that is performed and the discount is stored inside T.
03:28Now, as we got the discount that is 2,500, we also have to calculate the amount in which
03:36the customer purchased the goods. So here is the calculation work. n equals to P minus
03:42D. What is inside P? It is 25,000. What is inside D? It is 2,500. So from 25,000, 2,500
03:51is going to deduct and the amount is worth 22,500. In this amount, the customer purchased
04:00the good after deduction of discount. So good is purchased on this amount. Then we
04:08have displayed the discount in the net amount.
04:11Now, let us again run the program with some different amount. Suppose the purchasing amount
04:21of the second customer that is worth 500 and he made the purchase of only 500. So if
04:29500 greater than 10,000, here the condition will get false. It will come to the no part.
04:35And according to the question, if the purchase amount is less than 10,000, no discount. It's
04:40going to display what? No discount. And then what is stop?
04:47So in the next video, I'm going to implement the same program in C. Thanks.

Recommended