### Help please with receipt calculator!

How do I get this to work properly...

I want it to output the item price and sales tax and total with sales tax for each item the user enters.
And the item total, tax total and subtotal.

I managed to get the item total, tax total and subtotal to work just not listing individual items.

I want output to look like this:
-----------------------------------------
Item Cost Item Tax Item Subtotal
-----------------------------------------
0.00 0.00 0.00
0.00 0.00 0.00
0.00 0.00 0.00
0.00 0.00 0.00
0.00 0.00 0.00
-----------------------------------------
Item Total Tax Total Total Due
0.00 0.00 0.00

/////////////////////////////
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

int main()
{

//Variable
float item, cost, tax, subtotal;
double sales = 0.0;
int numSales = 0;
double totalSales = 0.0;

item = 0;

cout << "First sales amount (Enter a negative number to stop): ";
cin >> sales;

while (sales >= 0.0)

{
numSales = numSales + 1;

totalSales = totalSales +
sales;

cout << "Next sales amount (Enter a negative number to stop): ";
cin >> sales;
}
//end while

//Calculations

tax = totalSales * .07;
subtotal = tax + totalSales;

//Output
cout << "----------------------------------------- " << endl;
cout << " " << endl;
cout << " Receipt of Purchase" << endl;
cout << fixed << setprecision(2) << endl;
cout << "----------------------------------------- " << endl;
cout << setw(10) << "Item Cost" <<
setw(10) << "Item Tax" <<
setw(10) << " Item Subtotal" << '\n';
cout << "----------------------------------------- " << endl;
cout << setw(10) << "Item Total" <<
setw(10) << "Tax Total" <<
setw(10) << "Total Due" << '\n';
cout << setw(10) << totalSales <<
setw(10) <<tax <<
setw(10) <<subtotal << '\n';
cout << "----------------------------------------- " << endl;
cout << "You purchased " << numSales << " items." << endl;
cout << "----------------------------------------- " << endl;
cout << "Thank you! Have a nice day!" << endl;
cout << "----------------------------------------- " << endl;
//system("pause");
return 0;
}
//end of main function
@xokittenxo

In order to get the results you want, you would need to make a struct, or an array, as you are just adding everything together and have no way to separate each purchase to show on the receipt.

Here's one way of finishing your program..

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384`` ``````#include #include #include using namespace std; struct Item_Receipt { double item; double cost; double tax; double subtotal; }; int main() { vector Store_Receipt; Item_Receipt Purchase; //Variables const double item_tax = .08; // New York tax anyway. Change to your State Tax rate double Item_Total = 0.0; double Tax_Total = 0.0; double Total_Sales = 0.0; int numSales = 0; cout << "First sales amount (Enter a 0 to stop): "; cin >> Purchase.item; Purchase.tax = Purchase.item * item_tax; Purchase.subtotal = Purchase.item + Purchase.tax; Store_Receipt.push_back(Purchase); Item_Total += Purchase.item; Tax_Total += Purchase.tax; Total_Sales += Purchase.subtotal; numSales++; while (Purchase.item > 0.0) { cout << "Next sales amount (Enter a 0 to stop): "; cin >> Purchase.item; if(Purchase.item > 0.0) { Purchase.tax = Purchase.item * item_tax; Purchase.subtotal = Purchase.item + Purchase.tax; Store_Receipt.push_back(Purchase); Item_Total += Purchase.item; Tax_Total += Purchase.tax; Total_Sales += Purchase.subtotal; numSales++; } else cout << endl << "That was the last item being puchased.\nHere is your itemized receipt." << endl << endl; } //end while //Output cout << "----------------------------------------- " << endl; cout << "\tReceipt of Purchase" << endl; cout << "----------------------------------------- " << endl << endl; cout << fixed << setprecision(2); cout << setw(10) << "Item Cost" << setw(15) << "Item Tax" << setw(15) << "Subtotal" << '\n'; cout << "----------------------------------------- " << endl; for(int x=0;x> numSales; // Just to prevent screen from closing return 0; }``````
Last edited on
Thank you so much for your help. I knew I could make it into an array but I was having problems with the code. and I didn't know I could use a struct/ how to use it. Again thank you! I really appreciate it. I understand how to do this properly with a struct.
@xokittenxo

You're welcome. If you do have any questions or just want confirmation on a code section, please ask. I'll be glad to help out.
Topic archived. No new replies allowed.