Applying Discounts – Only 1 Volume Slab
Applying discounts on price based on only 1 quantity or volume of purchase based slab.
Learning Objectives
 Learning to handle one slab of discount with a simple ifelse.
 Learning multiple statements in both if and else conditions, thus using the scope { } braces properly.
 Learning to give instructions at the right place, inside or outside of the selection construct.
Source Code

Run Output
Code Understanding
float price,amount2pay;
These are currency related fields so they have been declared as float values.
int items,discount;
these are item quantity and discount related fields so they are taken as integer values. assumption is that items can not be partial and discount percentages are also whole numbers.
cout<<“Enter item price : “;cin>>price;
cout<<“Enter number of items purchased : “; cin>>items;
Item price and item puchase quantity are collected from the user.
if(items>=10) { discount=20; cout<<“Based on your purchase volume ” “you get a special discount”<<endl; }
Here we decide to give higher discount when the slab of purchase is equal to or higher than 10.
else {discount=10;cout<<“You get a regular discount”<<endl;}
When purchase is below the slab we give the regular discount.
cout<<“Your discount is “<<discount<<“%”<<endl;
Here we print the discount outside the selection statement as fixed within the true or false condition of the ifelse selection.
amount2pay=items*(priceprice*discount/100);
Here we calculate the final amout to pay. In this formula we assume that the discount is in percentage so we divide it by hundred. Then we calculate the discounted price of 1 item by subtracting the discount from the original price. Finally we multiply it by number of items to get the final amount to pay.
cout<<“Amount to pay = “<<amount2pay<<endl;
We finally print the calculated amount to be paid by the customer.
Notes
 The discount value could have been printed inside the selection construct also separately for if block and the else block. But this would be duplication of effort. So it is better to do it after the whole if and else block has finished. Just fixing the right discount amount inside the ifelse construct is the correct approach.
Suggested Filename(s): discount.cpp, discount1slab.cpp
sunmitra Created: 23Dec2017  Updated: 15Sep2018