Calculate the total sale given the unit price , quantity, discount and tax rate
Source Code:
Output:
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <iostream.h> #include <iomanip.h> #include <conio.h> const float cTaxRate = 8.50; int main () { cout << "\n Enter number of items sold: "; int quantity; cin >> quantity; cout << " Enter the unit price: "; float unitPrice; cin >> unitPrice; cout << " Enter the Discount Rate (Percent): "; float discountRate; cin >> discountRate; float subTotal = quantity * unitPrice; float discountAm = subTotal * discountRate / 100.0; float subTaxable = subTotal - discountAm; float taxAm = subTaxable * cTaxRate / 100.0; float total = subTaxable + taxAm; cout << fixed; cout << setprecision(2); cout << showpoint; cout << "\n Quantity sold: " << setw(6) << quantity << endl; cout << " Unit Price of items " << setw(9) << unitPrice << endl; cout << " -------------\n"; cout << "Subtotal : " << setw(9) << subTotal << endl; cout << "Discount : -" << setw(9) << discountAm << endl; cout << "Discounted Total: " << setw(9) << subTaxable << endl; cout << "Sales Tax : +" << setw(9) << taxAm << endl; cout << "Total sale : " << setw(9) << total << endl; getch(); return 0; } // main |
Output:
Enter number of items sold: 34 Enter the unit price: 12.89 Enter the Discount Rate (Percent): 7 Quantity sold: 34 Unit Price of items 12.89 ------------- Subtotal : 438.26 Discount : - 30.68 Discounted Total: 407.58 Sales Tax : + 34.64 Total sale : 442.23
No comments:
Post a Comment