Write a C++ program that inputs the price of a shoe in a shop, then deducts the discount from the price of the shoe as follows:
20% discount if the price of the shoe is above or equal 40 BD.
10% discount if the price of the shoe is more than or equal 15 BD and less than 40 BD.
5% discount if the price of the shoe is more than or equal 7 BD and less than 15 BD.
0% discount if the price of the shoe is below 7 BD.
Then, your program should output:
The initial shoe price, the discount amount and the final shoe price after discount.
All numbers should be displayed with 2 decimal places.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double discount,priceShoe;
cout<<"Enter the price of a shoe: ";
cin>>priceShoe;
//20% discount if the price of the shoe is above or equal 40 BD.
if(priceShoe>=40){
discount=priceShoe*0.2;
}
//10% discount if the price of the shoe is more than or equal 15 BD and less than 40 BD.
else if(priceShoe>=15 && priceShoe<40){
discount=priceShoe*0.1;
}
//5% discount if the price of the shoe is more than or equal 7 BD and less than 15 BD.
else if(priceShoe>=7 && priceShoe<15){
discount=priceShoe*0.05;
}
//0% discount if the price of the shoe is below 7 BD.
else{
discount=0;
}
double finalShoePrice=priceShoe-discount;
cout<<fixed<<"\nThe price of a shoe: "<<setprecision(2)<<priceShoe<<"\n";
cout<<"The discount of a shoe: "<<setprecision(2)<<discount<<"\n";
cout<<"The final shoe price after discount: "<<setprecision(2)<<finalShoePrice<<"\n";
cin>>discount;
return 0;
}
Comments
Leave a comment