Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have been asked to write a program to calculate sales totals for a general store. Your program will not know how many products each

You have been asked to write a program to calculate sales totals for a general store. Your program will not know how many products each customer will buy, so your program will have to repeat the process until the last product has been entered (use -1 for Product ID to end each sale). After each sale your program must ask if you want to do another sale (1 continue, 0 end program). At the beginning of the day, the cash drawer has $500 in it. At the end of the program you must display how much money is in the drawer after handling all your sales transactions.

int main() { double cashDrawer = 500.00; int productID = 0; int quantity = 0; double price = 0.0; double subtotal = 0.0; double salesTax = 0.0; double totalSale = 0.0; int anotherSale = 1; double taxrate = 0;

// Loop for repeat sales

????????? // Enter the first Product ID for the first sale (-1 to exit)

cout << "Enter the first product ID (-1 to exit): "; cin >> productID; cout << "Enter quantity of item purchased: " cin >> quantity;

// Main loop for each sale while (productID != -1) {

// Switch statement to determine the price, and calculate sales tax, switch(productID) { case 101: price = 65.0; taxrate = 0.075; break; case 102: price = 12.50; taxrate = 0.0; break; case 103: price = 24.50; taxrate = 0.0; break; case 104: price = 38.75; taxrate = 0.075; break;

case 105: price = 17.80; taxrate = 0.075; break;

case 106: price = 16.50; taxrate = 0.0; break;

case 107: price = 42.85; taxrate = 0.075; break;

case 108: price = 32.99; taxrate = 0.075; break;

case 109: price = 28.75; taxrate = 0.075; break;

case 110: price = 51.55; taxrate = 0.0; break; }

subtotal += quantity * price; salesTax = (quantity * price) * taxrate;

// Get next Product ID cout << "Enter the next product ID: "; cin >> productID;

}

// Print properly formatted output for each sale cout << "The total sale for this transaction is: " << subtotal << endl totalSale = subtotal + salesTax;

// Another sale? cout<<"if there is another sale press 1 to continue OR 0 to end: "; cin>>anotherSale;

// Display how much is in the cash drawer at the end

??????????

}

what is the best way to write the main loop for sales and output how much is in the cash drawer at the end?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions