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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <iomanip>
using namespace std;
//Global Variables
enum transType { SCAN_ITEM = 1, DISCOUNT, RECEIPT, EXIT};
const double TAX = 0.0825;
int main ()
{
cout.precision (2);
double itemPrice = 0.0, totalCost=0.0;
//initialize function variables
int choice, menuSelection;
double price, runningTotal, givenDiscount;
//initialize functions
double getDiscountRate(double discountRate);
double getPrice(double itemPrice, double totalCost);
void printReceipt(double totalCost, double discountRate);
int showMenu(int choice);
do {
showMenu(menuSelection);
switch (menuSelection)
{
case SCAN_ITEM:
getPrice (price, runningTotal);
break;
case DISCOUNT:
getDiscountRate(givenDiscount);
break;
case RECEIPT:
printReceipt(runningTotal, givenDiscount);
break;
case EXIT:
printReceipt(runningTotal, givenDiscount);
cout << "System Exit\n" << endl;
break;
}
} while (menuSelection != EXIT);
system ("pause");
return 0;
}
//Functions
int showMenu(int choice)
{
cout << "Supermarket POS System\n"
<< "----------------------------------\n"
<< "Select an option:\n"
<< SCAN_ITEM << ". Scan an Item\n"
<< DISCOUNT << ". Set Discount Rate\n"
<< RECEIPT << ". Print Receipt\n"
<< EXIT << ". Exit\n"
<< "\n >>";
cin >> choice;
return (choice);
}
double getPrice(double itemPrice, double totalCost)
{
do {
cout << "Enter the item price (positive number only): ";
cin >> itemPrice;
if (itemPrice <= 0) {
cout << "Please enter a positive number only.\n" << endl;
}
else {
totalCost += itemPrice;
cout << "Running Total: " << fixed << totalCost << "\n" << endl;
}
} while (itemPrice <= 0);
return (totalCost);
}
double getDiscountRate(double discountRate)
{
cout << "Enter the Discount Rate (0.0-1.0): ";
cin >> discountRate;
cout << "Customer discount is at " << discountRate*100 <<"% off.\n" << endl;
return (discountRate);
}
void printReceipt(double totalCost, double discountRate)
{
double discountTotal, taxTotal;
discountTotal = totalCost*discountRate;
taxTotal = (totalCost-discountTotal)*TAX;
cout << "Total Purchase:\t " << setw(8) << totalCost << "\n";
if (discountRate > 0) {
cout << "Discount:\t" << "-" << setw(8) << discountTotal << "\n";
}
cout << "Tax:\t\t" << "+" << setw(8) << taxTotal << "\n";
cout << "Total Charge:\t" << "=" << setw(8) <<totalCost - discountTotal + taxTotal << "\n" << endl;
}
|