Breakfast Menu using loops and functions

I almost have this figured out. The only problem I am having is if the person orders and then when it is time to pay, the person does not give enough money. I can get it to display the new total but if the person does not give enough money again thats where it wont work. I will make an arrow to where I THINK the problem in the code is.

[code]
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

double total;
double pay;
double change;
double owe;
double tax;

int selection(int choice, double subTotal)
{
cout << "Welcome to Braden's Breakfast of Champions" << endl;
cout << "Enter from the menu below" << endl;
cout << "1. Eggs" << endl;
cout << "2. Pancakes" << endl;
cout << "3. Bacon" << endl;
cout << "4. Waffles" << endl;
cout << "5. Coffee" << endl;
cout << "6. Buscuits" << endl;
cout << "7. Orange Juice" << endl;
cout << "8. Sausage" << endl;
cout << "9. Steak" << endl;
cout << "10. Milk" << endl;
cout << "Subtotal: $" << subTotal << endl;
cout << "Enter Selection (0 to exit): ";
cin >> choice;
return choice;
}



double menuItem(int choice, int quantity, double subTotal)
{
if(choice==1)
subTotal = subTotal + 1.00 * quantity;
if(choice==2)
subTotal = subTotal + 1.99 * quantity;
if(choice==3)
subTotal = subTotal + 1.49 * quantity;
if(choice==4)
subTotal = subTotal + 2.99 * quantity;
if(choice==5)
subTotal = subTotal + 1.00 * quantity;
if(choice==6)
subTotal = subTotal + 1.49 * quantity;
if(choice==7)
subTotal = subTotal + 1.99 * quantity;
if(choice==8)
subTotal = subTotal + 2.49 * quantity;
if(choice==9)
subTotal = subTotal + 4.99 * quantity;
if(choice==10)
subTotal = subTotal + 1.49 * quantity;
return subTotal;
}

double receipt(double subTotal)
{

tax = .10;
tax = tax * subTotal;
total = tax + subTotal;

cout << "Recept for Today's Breakfast item purchase" << endl;
cout << "Subtotal: $" << subTotal << endl;
cout << "Tax: $" << tax << endl;
cout << "Total: $" << total << endl;

return total;

}


int main()
{
cout << fixed << showpoint << setprecision(2);
int choice = 99, quantity;
double subTotal = 0, change = 0, total = 0;

while(choice!=0)
{
system("cls");

choice = selection(choice, subTotal);

if(choice!=0)
{
cout << "Enter Number of items you want to purchase: ";
cin>> quantity;

subTotal = menuItem(choice,quantity,subTotal);

}



}


system("cls");
total=receipt(subTotal);




cout << "Amount paid: $";
cin >> pay;

while(pay<total) //<------------------ PROBLEM AREA----------
{
owe = total - pay;
cout << "You owe: $" << owe << endl;
cout << "Amount paid: $" << endl;
cin >> pay;

if(owe<total)
{
cout << "You owe: $" << owe << endl;
cout << "Amount paid: $" << endl;
cin >> pay;

}







} //<---------- PROBLEM AREA --------------



// make the receipt
receipt(subTotal);

change = pay - total;
cout << "Change: $" << change << endl;



system("pause");
return 0;
}

/*
for a restaurant menu system for breakfast items

Items:
1. eggs
2. pancakes
3. bacon
4. waffles
5. coffee
6. buscuits
7. orange juice
8. sausage
9. steak
10. milk

We want our program to prompt a cashier to enter the customer's selection(s). It should loop while the customer is adding more items. As it is looping, it is useful to displa
y the customer's
current subtotal on the screen.When completed, the program should generate a receipt for the customer which will have a tax of 10% and a total amount due.
*/

I marked the "problem area". I just need the code to keep looping until the customer pays enough money to complete the purchase. Thanks!!
Initialize owe outside the loop and subtract the payment from the amount owed each time:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
total=receipt(subTotal);
owe = total;
do {
    cout << "Amount paid: $";
    cin >> pay;
    owe -= pay;

    if(owe > 0) {
        cout << "You owe: $" << owe << endl;
    }
} while (owe > 0);

// ...
change = -owe;

Gahhhhh That makes so much more since. I tried something like this extremely close to this solution. Thanks sooooooo much!!!
Topic archived. No new replies allowed.