Can someone check over this for me and see if its correct i still don't have my book lol
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 (Y –continue, N – 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.
Input
Your program must take the following input:
• Product ID Number (int)
• Quantity for each item purchased (int)
• Cash Received at the end of the sale
Use the following dataset to determine the price and taxability for each item.
First Sale:
Product ID Price Quantity Taxable
101 $65.00 2 Yes
102 $12.50 1 No
103 $24.50 5 No
104 $38.75 4 Yes
105 $17.80 6 Yes
106 $16.50 2 No
107 $42.85 8 Yes
108 $32.99 2 Yes
109 $28.75 1 Yes
110 $51.55 1 No
Second Sale:
Product ID Price Quantity Taxable
102 $12.50 1 No
103 $24.50 1 No
106 $16.50 1 No
107 $42.85 1 Yes
108 $32.99 1 Yes
109 $28.75 1 Yes
Third Sale:
Product ID Price Quantity Taxable
106 $16.50 4 No
107 $42.85 3 Yes
108 $32.99 1 Yes
109 $28.75 5 Yes
110 $51.55 2 No
Can someone check over this for me and see if its correct i still don't have my book lol
#include <iostream>
using namespace std;
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;
int i = 1;
// Loop for repeat sales.Assume we have atleast one sale.
while(anotherSale != 0)
{
// Enter the first Product ID for the first sale (-1 to exit)
subtotal = 0.0;
salesTax = 0.0;
cout<<"Enter the first Product ID: ";
cin>>productID;
// Main loop for each sale
while(productID != -1)
{
cout<<"Enter the quantity sold of type productID "<<productID<<": ";
cin>>quantity;
// Switch statement to determine the price, and calculate sales tax, if any, for the item.
switch(productID)
{
case 101:
price = 65.00;
salesTax += price * 0.075 * quantity;
break;
case 102:
price = 12.50;
break;
case 103:
price = 24.50;
break;
case 104:
price = 38.75;
salesTax += price * 0.075 * quantity;
break;
case 105:
price = 17.80;
salesTax += price * 0.075 * quantity;
break;
case 106:
price = 16.50;
break;
case 107:
price = 42.85;
salesTax += price * 0.075 * quantity;
break;
case 108:
price = 32.99;
salesTax += price * 0.075 * quantity;
break;
case 109:
price = 28.75;
salesTax += price * 0.075 * quantity;
break;
case 110:
price = 51.55;
salesTax += price * 0.075 * quantity;
break;
default:
cout<<"Invalid ProductID."<<endl;
}
subtotal += salesTax + price * quantity;
// Get next Product ID
cout<<"Enter the next Product ID: ";
cin>>productID;
}
// Print properly formatted output for each sale
cout<<"The total of this sale is: "<<subtotal<<"."<<endl;
totalSale += subtotal;
// Another sale?
cout<<"Do you have another sale(1. Continue, 0. End): ";
cin>>anotherSale;
}
cashDrawer += totalSale;
// Display how much is in the cash drawer at the end
cout<<"The balance in the cash drawer is: "<<cashDrawer<<"."<<endl;
}
(extra info)
If you want me to put in results let me know i need all the help i can get this project is due sunday
My observations and suggestions: I would add the variable constdouble cashDrawerStart{500.0}; followed by constdouble tax{0.075};. These are two variables you do not want to accidentally change in the program. In the switch section change the "0.075" to tax and the formula is better stated salesTax += price * quantity * tax;. The way you have it might cause the actual sales tax to be off.
After the switch the line: subtotal += salesTax + price * quantity;
should just be subtotal += price * quantity;
because you add the sales tax to the sub total not into the sub total.
The last thing I did was to move the line totalSale += subtotal + salesTax;
to above the cout statements so that it would figure the total before it printed the total.
A little formatting of the final output and the program seemed to run OK.