Cash Register Program
Oct 12, 2014 at 9:45pm UTC
Hello, I am struggling on this part of my program. It says: You should have a function, let’s call it MakeSale(), that accepts no arguments and returns the total amount of the sale (including tax). All the input needed to make a sale should be requested from user inside MakeSale() function.
So far this is what I have. I am unsure how to return my total value so that it adds up the amount of items that the user has entered. Basically, I need "Item Price Tax: $" and "Price of Weighted Item: $" to add up within the MaleSale () function. Any suggestions would be helpful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#include <iostream>
using namespace std;
// function prototype
double MakeSale();
int main()
{
//Input
double total = 0;
int count = 0;
int choice = 1;
while (choice != 0)
{
cout << "Welcome to Cash Register v2.0" << endl;
cout << "=============================" << endl;
cout << "1- New Sale" << endl;
cout << "2- Cash In" << endl;
cout << "3- Cash Out" << endl;
cout << "4- Report" << endl;
cout << "0- Exit" << endl;
cout << "What do you want to do: " ;
cin >> choice;
if (choice == 1)
{
int itemCount;
cout << "How many items in this sale: " ;
cin >> itemCount;
for (int i = 0; i < itemCount; i++)
{
int itemCode;
cout << "Item Code: " ;
cin >> itemCode;
if (itemCode < 100)
{
double itemPP;
cout << "Item Price/Pound: " ;
cin >> itemPP;
double itemWeight;
cout << "Item Weight: " ;
cin >> itemWeight;
double computeprice = itemPP * itemWeight;
cout << "Price of Weighted Item: $" << computeprice << endl;
}
else
{
double itemPrice;
cout << "Item Price: " ;
cin >> itemPrice;
double Tax = itemPrice * 0.1;
cout << "Item Price Tax: $" << Tax << endl;
}
}
}
else if (choice == 2)
{
double cash;
cout << "Cash-in amount: " ;
cin >> cash;
total = total + cash;
}
else if (choice == 3)
{
double cash;
cout << "Cash-out amount: " ;
cin >> cash;
total = total - cash;
}
else if (choice == 4)
{
}
}
system("PAUSE" );
return 0;
}
double MakeSale()
{
}
Last edited on Oct 12, 2014 at 9:55pm UTC
Oct 12, 2014 at 9:55pm UTC
It sounds like what you do is just put what you have in choice == 1 into the function and have it return the price of all the items including the tax.
Oct 12, 2014 at 9:59pm UTC
That is what I am unsure how to do
Oct 12, 2014 at 10:11pm UTC
So basically take all you have in choice == 1 and put it into the function. Then when the choice == 1, then call the function and have it equal to a double variable (since the function is returning a double). Then print out this variable like you originally have it at the end of choice == 1.
Oct 12, 2014 at 10:20pm UTC
Do you mean like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#include <iostream>
using namespace std;
// function prototype
double MakeSale(double );
int main()
{
//Input
double total = 0;
int count = 0;
int choice = 1;
while (choice != 0)
{
cout << "Welcome to Cash Register v2.0" << endl;
cout << "=============================" << endl;
cout << "1- New Sale" << endl;
cout << "2- Cash In" << endl;
cout << "3- Cash Out" << endl;
cout << "4- Report" << endl;
cout << "0- Exit" << endl;
cout << "What do you want to do: " ;
cin >> choice;
if (choice == 1)
{
MakeSale();
}
else if (choice == 2)
{
double cash;
cout << "Cash-in amount: " ;
cin >> cash;
total = total + cash;
}
else if (choice == 3)
{
double cash;
cout << "Cash-out amount: " ;
cin >> cash;
total = total - cash;
}
else if (choice == 4)
{
}
}
system("PAUSE" );
return 0;
}
double MakeSale(double )
{
double total = 0;
int itemCount;
cout << "How many items in this sale: " ;
cin >> itemCount;
for (int i = 0; i < itemCount; i++)
{
int itemCode;
cout << "Item Code: " ;
cin >> itemCode;
if (itemCode < 100)
{
double itemPP;
cout << "Item Price/Pound: " ;
cin >> itemPP;
double itemWeight;
cout << "Item Weight: " ;
cin >> itemWeight;
double computeprice = itemPP * itemWeight;
cout << "Price of Weighted Item: $" << computeprice << endl;
}
else
{
double itemPrice;
cout << "Item Price: " ;
cin >> itemPrice;
double tax = itemPrice * 0.1;
cout << "Item Price Tax: $" << tax << endl;
}
}
return ;
}
Oct 12, 2014 at 10:25pm UTC
Mostly, you would want to return the total of the computeprice and tax in the return statement. Then you would want to use that by printing it out in a cout statement.
Oct 12, 2014 at 10:48pm UTC
Are we able to write return total = computetax + tax; ?
This is the first time returning something besides 0, sorry. :(
Oct 12, 2014 at 10:52pm UTC
In a sense yeah. But you need the loop to keep track of all tax and computeprice to be able to be added into the returned total.
Topic archived. No new replies allowed.