Write a program that simulates
a simple cash register. It should ask the user if a customer is to be
processed. If the user responds yes, prompts the user to enter the
price of the meal. Then it calculates the sales tax (8% of the meal price)
and the total price, which it should display to the user. Next, it asks the
user to enter the amount tendered, and displays the amount tendered, the total
price, and the customer’s change. The program then asks the user if there is
another customer to process. If the user responds yes, the program processes the
next customer in the same way. This procedure continues indefinitely until the
user responds no to the prompt for another customer. Finally, the program
displays the total number of customers it processed and the grand total of all the
meal prices. Input Validation: Do not accept a number less than 1 for the price of the meal. Do not accept a value for the amount tender that is less than the total price.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double change, totalAmount, amount, price, tax;
double SALES_TAX = .08;
char choice, selection;
cout << "Would you like to process a transaction? (Y/N) ";
cin >> selection;
if (selection == 'y' || selection == 'Y')
{
do
{
cout << " \nPrice of the meal $ ";
cin >> price;
tax = SALES_TAX * price;
totalAmount = price + tax;
cout << setprecision(2) << fixed;
cout << " \nSales tax $ " << tax << endl
<< endl;
cout << "totalAmount amount $ " << totalAmount << endl;
cout << "\nAmount:";
cin >> amount;
if (amount > totalAmount)
{
cout << setprecision(2) << fixed;
change = amount - totalAmount;
cout << " \nChange $ " << change << endl;
}
else if (amount < totalAmount)
{
cout << " \nError: Amount have to be more than the total bill " << endl;
}
else if (amount == totalAmount)
{
cout << "\nChange $ 0.00" << endl;
}
cout << "\n\nDo you want to process another transaction? (Y/N) ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
cout << "\nThe End" << endl
<< endl;
}
else
cout << "\nThe End" << endl
<< endl;
return 0;
}
Comments
Leave a comment