My assignment is to write a program to calculate sales total. My program will not know how many products each customer will buy, so it will have to repeat the process until a last product has been entered (I am suppose to use -1 for product ID to end each sale). After each sale my program is suppose to ask if they want to do another sale (y-continue, N-end program). The cashDrawer will have $500.00 in it. I must display how much money is in the drawer after handling all sales transactions.Below is my code and it does not work. Please help. This is due tonight at 9pm.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//function main begins program execution
int main()
{
double cashDrawer = 500.00;
int productID = 0;
double price = 0.0;
double subtotal = 0.0;
double salesTax = 0.0;
double total = 0.0;
char anotherSale = 'y';
int quantity = 0;
double taxRate = 0;
// Loop for repeat sales
while (anotherSale == 'y')
{
double price = 0.0;
double subtotal = 0.0;
double salesTax = 0.0;
double total = 0.0;
int quantity = 0;
double taxRate = 0;;
// Enter the first Product ID for the first sale (-1 to exit)
cout << "Enter the product ID or -1 to quit: " << endl;
cin >> productID;
cout << "Enter quantity: " << endl;
cin >> quantity;
// Main loop for each sale
while (productID != -1)
{
// Switch statement to determine the price, and calculate sales tax, if any, for the item.
switch (productID)
{
case 101:
price = 65.00;
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;
default:
cout << "You have entered an incorrect product ID." << endl;
}
subtotal += (quantity * price) + (quantity * price * taxRate);
total = subtotal + total;
}
subtotal += (quantity * price) + (quantity * price * taxRate);
total = subtotal + total;
}
// Get next Product ID
cout << "Enter the next product ID or -1 to quit: " << endl; //prompt user for input
cin >> productID;
cout << "Enter quantity: " << endl;
cin >> quantity;
//}
// Print properly formatted output for each sale
cout << "The subtotal is: " << subtotal <<endl;
cout << "The total is " << total << endl;
cout << "Would you like to do another sale? (y-Continue, n-End Program)" << endl;
cin >> anotherSale;
// Display how much is in the cash drawer at the end
cashDrawer = cashDrawer + total;
cout << "The money in the drawer after handling all transactions is " << cashDrawer << endl;
system ("pause");
return 0;
}
Unfortunately, your question requires a lot of work and cannot be done for free.
Submit it with all requirements as an assignment to our control panel and we'll assist you.