I'm creating this C receipt program and i'm trying to loop it using the goto statement but whenever i the program goes back to menu: using the goto statement it seems to bypass the getline statement i used thus it doesn't ask for the string whenever it asks for an order from the menu again, maybe you'll be able to see what's wrong just by looking at the program need tips and advice thanks!
#include <iostream>
#include <string>
using namespace std;
void main ()
{
string product;
char decision;
double price,pcs,total,paid,change=0;
menu:
cout <<"Place Your Order Now: " <<endl;
cout <<"=====================================... <<endl;
cout <<"Enter Product: " ;
getline (cin,product);
cout <<"Enter the Price: P" ;
cin >> price;
cout <<"Enter Number of Pieces: " ;
cin >> pcs;
total = price * pcs;
cout <<"=====================================... <<endl<<endl;
cout <<product;
cout <<endl<<endl;
cout <<"Total Amount Due = P" <<total <<endl;
cout <<"=====================================... <<endl;
cout <<"Enter Payment: P";
cin >> paid;
cout <<"=====================================... <<endl;
change = paid - total;
cout <<"Change = P" << change;
cout <<endl <<endl <<"01 James Lim C example" <<"\n" <<"\n";
cout <<"Would you like to order again? <y> yes <n> no = ";
cin >>decision;
if (decision == 'y' || decision == 'Y')
goto menu;
else if (decision == 'n' || decision == 'N')
goto quit;
else
cout <<"invalid input! \n";
goto menu;
quit:
cout <<"Thank you! Please come again! \n";
}
Tags: