Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This project will ask the user for 5 items and costs of each,
- and then output the total price in a neat and tidy table */
- // TableProject
- // 2-8-12
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main () {
- int item1, item2, item3, item4, item5;
- double price1, price2, price3, price4, price5, totalItems;
- double totalPrice, avgPrice;
- cout << "\t\tThis program creates a nicely formatted table.\n"
- << " By Nessie Murray \n\n";
- cout << "Quantity of product #1: ";
- cin >> item1; cin.ignore(80, '\n');
- cout << "Price of product #1: ";
- cin >> price1; cin.ignore(80, '\n');
- cout << "\n";
- cout << "Quantity of product #2: ";
- cin >> item2; cin.ignore(80, '\n');
- cout << "Price of product #2: ";
- cin >> price2; cin.ignore(80, '\n');
- cout << "\n";
- cout << "Quantity of product #3: ";
- cin >> item3; cin.ignore(80, '\n');
- cout << "Price of product #3: ";
- cin >> price3; cin.ignore(80, '\n');
- cout << "\n";
- cout << "Quantity of product #4: ";
- cin >> item4; cin.ignore(80, '\n');
- cout << "Price of product #4: ";
- cin >> price4; cin.ignore(80, '\n');
- cout << "\n";
- cout << "Quantity of product #5: ";
- cin >> item5; cin.ignore(80, '\n');
- cout << "Price of product #5: ";
- cin >> price5; cin.ignore(80, '\n');
- cout << "\n\n";
- totalPrice = (item1 * price1) + (item2 * price2) + (item3 * price3)
- + (item4 * price4) + (item5 * price5);
- totalItems = item1 + item1 + item3 + item4 + item5;
- avgPrice = (price1 + price2 + price3 + price4 + price5) / 5;
- cout << " Product # Quantity Price Total\n";
- cout << " =======================================================\n"
- << setw(9) << "1" << setw(15) << item1 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price1 << setw(6) << "$" << setw(11) << item1 * price1 << endl
- << setw(9) << "2" << setw(15) << item2 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price2 << setw(6) << "$" << setw(11) << item2 * price2 << endl
- << setw(9) << "3" << setw(15) << item3 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price3 << setw(6) << "$" << setw(11) << item3 * price3 << endl
- << setw(9) << "4" << setw(15) << item4 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price4 << setw(6) << "$" << setw(11) << item4 * price4 << endl
- << setw(9) << "5" << setw(15) << item5 << setw(10) << "$" << setw(8) << fixed << setprecision(2) << price5 << setw(6) << "$" << setw(11) << item5 * price5 << endl;
- cout << setw(11) << "TOTAL" << setw(14) << totalItems << setw(6) << "$" << setw(7) << fixed << setprecision(2) << avgPrice << setw(10) << totalPrice;
- cout << "\n\n";
- system ("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment