help with loop

can someone help me with loop dunno which one to use and how to start.
i basically want this program to loop the "enter money" part if the "else" is true

also if u have a better way to make a similar program please do tell thanks

here is the program...

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
#include <iostream>
using namespace std;
 
int main()
{

int burger=5, price, choice, money, change;

cout<<"5 DOLLAR BURGERS"<<endl<<endl;

cout<<"press 1 add cheese (1 dollars)"<<endl;
cout<<"press 2 add coleslaw (2 dollars)"<<endl;
cout<<"press 3 add cheese and coleslaw (3 dollars)"<<endl;
cout<<"choose dressing... ";
cin>>choice;

switch(choice) 
{
	case 1: price=burger+1;		
		break;
	case 2: price=burger+2;
		break;
	case 3: price=burger+3;
		break;
	default: cout<<endl<<"we dont have that! exiting..."<<endl;
	return 0;
		break;
		
}

cout<<endl<< "that will be "<<price; cout<<" dollars"<<endl;

cout<<"enter money ";
cin>>money;

change=money-price;

if (money>price)
cout<<"your change is "<<change<<endl<<endl;

else if (money==price)
cout<<"you have the exact amount thank you for shopping!"<<endl<<endl;

else
cout<<"insufficient cash, please enter the corect amount"<<endl<<endl;
 
    return 0;
}
Last edited on
nevermind, got it to work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
do{
cout<<"enter money ";
cin>>money;

change=money-price;


if (money>price)
cout<<"your change is "<<change<<endl<<endl;

else if (money==price)
cout<<"you have the exact amount thank you for shopping!"<<endl<<endl;

else
cout<<"insufficient cash, please enter the corect amount"<<endl<<endl;
}while (money<price);
    return 0;
}
Topic archived. No new replies allowed.