Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 5.17 Calculating Sales
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019 */
- #include<iostream>
- using namespace std;
- int main() {
- int itemNum{ 0 }, quant;
- double total{ 0.0 };
- while (true) {
- cout << "Please enter item # (1-5). Enter 6 to end.\n";
- cin >> itemNum;
- if (itemNum < 1 || itemNum > 6) {
- cout << "Invalid item.\n\n";
- continue;
- }
- if (itemNum == 6) {
- cout << "\nDone purchasing. Calculating order...\n\n";
- break;
- }
- cout << "Please enter the quantity of item " << itemNum << " you wish to buy\n";
- cin >> quant;
- switch (itemNum) {
- case 1:
- cout << "These are $2.98 each\n";
- total += quant * 2.98;
- cout << "Your running total is now: " << "$"<< total << "\n\n";
- break;
- case 2:
- cout << "These are $4.50 each\n";
- total += quant * 4.50;
- cout << "Your running total is now: " << "$"<< total << "\n\n";
- break;
- case 3:
- cout << "These are $9.98 each\n";
- total += quant * 9.98;
- cout << "Your running total is now: " << "$"<< total << "\n\n";
- break;
- case 4:
- cout << "These are $4.49 each\n";
- total += quant * 4.49;
- cout << "Your running total is now: " << "$" << total << "\n\n";
- break;
- case 5:
- cout << "These are $6.87 each\n";
- total += quant * 6.87;
- cout << "Your running total is now: " << "$" << total << "\n";
- break;
- }
- }
- cout << "Total cost: " << total << "\n\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment