Sample Program 2

 

 

Problem Statement

 

A shopkeeper announces a package for customers that he will give 10 % discount on all bills and if a bill amount is greater than 5000 then a discount of 15 %. Write a C program which takes amount of the bill from user and calculates the payable amount by applying the above discount criteria and display it on the screen.

 

Solution

In this problem we are going to make decision on the basis of the bill amount, so we will be using if statement. We declare three variables amount, discount and netPayable and initialize them. Next we prompt the user to enter the amount of the bill. After this we implement the if statement to test the amount entered by the user. As we see in the problem statement that if the amount is greater than 5000 then the discount rate is 15 % otherwise (i.e. the amount is less than or equal to 5000) the discount rate is 10 %. So we check the amount in if statement. If it is greater than 5000 then the condition is true then the if block is executed otherwise if amount is not greater than 5000 then the else block is executed.

The analysis and the flow of the program is shown by the following flow chart. 

 

 

 

 

 

 

 

Previous

 

 

TOC

 

 

Next