Input purchase price and calculate discount in C++
if else if - Question 11
In this question, we will see how to input the purchase amount and print the discount amount and the net bill amount after deducting the discount amount in C++ programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q11) A showroom gives discount according to the following slab rates on the purchase amount.
Purchase Amount | Discount |
Up to 5,000 | No Discount |
5,001 to 10,000 | 10% of the amount exceeding 5000 |
10,001 to 20,000 | 20% of the amount exceeding 10,000 |
20,001 to 30,000 | 30% of the amount exceeding 20,000 |
More than 30,000 | 40% of the amount exceeding 30,000 |
Write a program in C++ to input the purchase amount and print the discount amount and the net bill amount after deducting the discount amount.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int p;
float dis;
cout<<"Enter purchase amount ";
cin>>p;
if(p<=5000)
{
dis=0;
}
else if(p>5000 && p<=10000)
{
dis=(p-5000)*(10/100.0);
}
else if(p>10000 && p<=20000)
{
dis=(p-10000)*(20/100.0);
}
else if(p>20000 && p<=30000)
{
dis=(p-20000)*(30/100.0);
}
else
{
dis=(p-30000)*(40/100.0);
}
cout<<"Discount Amount = "<<dis<<endl;
cout<<"Net Bill Amount = "<<p-dis;
return 0;
}
Output
Enter purchase amount 25648 Discount Amount = 1694.4 Net Bill Amount = 23953.6