Devmen
06-29-2007, 06:54 AM
Hi im new to c++ (taking a class) and im trying to make a cash register program that takes the cost of items, sums it up, adds tax, and gives a result. I want to use a loop, either for or while, but im having difficulty.
this is what i have
int main()
{
float item, cost, tax, subtotal, grandtotal;
//Declared Variable
item = 0;
cout.precision(4);
for (int x = 0; x < 1; item++)
{
cout << "Enter the cost of the item in $: "; // prompt for cost of the item
cin >> cost; // input cost
subtotal = cost + subtotal; // adds item cost the the subtotal
if(cost == 0) // ends loop if 0 is entered
x = 1;
}
tax = subtotal * .07; // computes tax
subtotal = tax + subtotal; //adds tax to the cost
cout << "Your Total is: " << subtotal << " with " << item << " item(s)\n";
return 0;
}
as of now im stuck, when i try to stop the loop so that it sums up and adds tax the program terminates. thanks in advance for help!
this is what i have
int main()
{
float item, cost, tax, subtotal, grandtotal;
//Declared Variable
item = 0;
cout.precision(4);
for (int x = 0; x < 1; item++)
{
cout << "Enter the cost of the item in $: "; // prompt for cost of the item
cin >> cost; // input cost
subtotal = cost + subtotal; // adds item cost the the subtotal
if(cost == 0) // ends loop if 0 is entered
x = 1;
}
tax = subtotal * .07; // computes tax
subtotal = tax + subtotal; //adds tax to the cost
cout << "Your Total is: " << subtotal << " with " << item << " item(s)\n";
return 0;
}
as of now im stuck, when i try to stop the loop so that it sums up and adds tax the program terminates. thanks in advance for help!