Write a program in c++ to calculate the final cost of items purchased with a dis
ID: 3870798 • Letter: W
Question
Write a program in c++ to calculate the final cost of items purchased with a discount applied. Prompt the user for three inputs: Cost per item Number of items purchased Discount rate A tax rate of 7 percent should be defined as a constant and the tax rate variable should be used for calculating the tax amount The following should be calculated and outputted in the following order: Total cost before discount and before tax Discount amount Cost after the discount amount is applied Tax amount Final cost
Explanation / Answer
#include<iostream>
using namespace std;
int main(){
float itemCost,numOfitems,discount,tax=7,tcost,costaftdisc;
cout << "Enter ItemCost:";
cin >> itemCost;
cout << "Enter number of items:";
cin >> numOfitems;
cout << "Enter discount:";
cin >> discount;
tcost = itemCost*numOfitems;
cout << "Total Cost before discount : " << (tcost) + (tcost)*(tax/100) << endl;
cout << "Total Cost before tax : " << (itemCost*numOfitems) << endl;
cout << "Discount amount : " << (tcost)*(discount/100) << endl;
costaftdisc = (tcost) - (tcost)*(discount/100) ;
cout << "Total Cost After discount : " << costaftdisc << endl;
cout << "Tax amount : " << (costaftdisc)*(tax/100) << endl;
cout << "Final cost : " << (costaftdisc) + (costaftdisc)*(tax/100) << endl;
return 0;
}
/*
sample output
Enter ItemCost: 10
Enter number of items: 10
Enter discount: 10
Total Cost before discount : 107
Total Cost before tax : 100
Discount amount : 10
Total Cost After discount : 90
Tax amount : 6.3
Final cost : 96.3
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.