In: Computer Science
C++ program:
ABC Co wants you to develop a C++ program to calculate the total invoice based on the user inputs item price and the quantity of the item purchased, taking into consideration the discount given for each category as follow:
Your Program should display, the total before discount, how much discount and the total after discount.
input code:
output
code
#include <iostream>
using namespace std;
int main()
{
/*declare the variables*/
int n;
double price,discount,total;
/*take user input*/
cout<<"Enter the price: ";
cin>>price;
cout<<"Enter the quantity: ";cin>>n;
/*find discount*/
if(n<10)
{
discount=0;
}
else if(n<=20)
{
discount=price*n*0.1;
}
else
{
discount=price*n*0.2;
}
/*print output*/
total=price*n;
cout<<"Total before discount :
$"<<total<<endl;
cout<<"discount : $"<<discount<<endl;
cout<<"Total after discount : $"<<total-discount;
return 0;
}