Question: Beginners C++ Question. A customer makes a purchase at the store. The tax rate is 8% on all purchases except groceries. The store offers a
Beginners C++ Question.
A customer makes a purchase at the store. The tax rate is 8% on all purchases except groceries. The store offers a 5% discount to seniors 60 and over. You should ask the user three questions: what they have bought (use a menu displaying bread, milk, or soap), what the purchase price is, and how old they are. Your goal is to print a formatted invoice with the following line items: price, tax, discount, and total. The discount should only be printed if applicable. How to calculate the tax and the discount?
#include
using namespace std; int main() { // Constants for the range of valid choices const int MIN_VALID_CHOICE = 1; const int MAX_VALID_CHOICE = 3; // 5% senior discount const double SENIOR_RATE = 0.05; // 8% tax const double Tax = 0.08; //&& means it must be inside the range. 1 && 9, the range will be between 1 and 9
// Formatting constants const int PRECISION = 2; // Display the menu and get a choice. cout << "\tWhat would you like to buy?" << endl; cout << "1. Bread" << endl; cout << "2. Milk" << endl; cout << "3. Soap" << endl << endl; // Ask the user for a choice of above. cout << "Enter your choice: "; int choice; cin >> choice; //ask the user for their age cout << "Please enter your age: "; int age; cin >> age;
// Ask the user for the number of months. cout << "Please enter the price $"; int Price; cin >> Price;
// Respond to the user's menu selection. if (choice < MIN_VALID_CHOICE || choice > MAX_VALID_CHOICE) { // Output an error message. cout << "The valid choices are " << MIN_VALID_CHOICE << " through "<< MAX_VALID_CHOICE << endl; cout << "Please run the program again and select a valid choice" << endl; }
// double newprice; // double total = 0; // newprice = Price*Tax; // total = newprice + Price; double total = 0; // Determine the rate based on the user's choice. if (age >=60){ } if (choice == 1 || choice == 2 ) { } else if ( choice == 3) { } else // Format the output. cout << fixed << showpoint << setprecision(PRECISION); // Output the result. cout << setw(20) << "Invoice" << endl; cout << endl; cout << "Price $ $" << setw(10) << Price << endl; cout << "Tax $" << setw(15) << Tax << endl; cout << "total $" << setw(13) << total << endl; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
