How would i loop??

How would i loop the main menu with code???
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
// This Program is for Frederick A. Bowser
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;
int main ()
{
	const string menu = " [01] Meat	   [02] Bakery  [03] Fruits     [04] Frozen \n"
	" [05] Milk & Diary [06] Drinks	[07] Cereal	[08] Snacks \n";
	cout << menu << endl;
cout << "______________________________________________________________________________" << endl;
	int choice;
	cout << "Which would you like = " << endl;
	cin >> choice;
	switch (choice)
		{case 1: 
	cout <<  " [01] bacon	[02] hotdog  [03] beef   [04] steak \n";
	int meat;
	meat = 1,2,3,4;
	cout << "Which Meat would you like? \n";
		cin >> meat;
		if (meat ==1)
		{ int quantity;
			cout << "How much bacon? = \n";
			cin >> quantity;
			cout << "___________________________________________________________________" <<endl;
			double total;
			total = quantity* 1.22;
			cout << "Your total is = $" << total << endl;}
		else if (meat ==2)
		{ int quantity;
			cout << "How much hotdogs? = \n";
			cin >> quantity;
			cout << "___________________________________________________________________" <<endl;
			double total;
			total = quantity* 1.15;
			cout << "Your total is = $" << total << endl;}
		else if (meat ==3)
		{ int quantity;
			cout << "How much beef? = \n";
			cin >> quantity;
			cout << "___________________________________________________________________" <<endl;
			double total;
			total = quantity* 3.20;
			cout << "Your total is = $" << total << endl;}
		else if (meat ==4)
		{ int quantity;
			cout << "How much steak? = \n";
			cin >> quantity;
			cout << "___________________________________________________________________" <<endl;
			double total;
			total = quantity* 4.75;
			cout << "Your total is = $" << total << endl;}
		
	
				break;
				}
return 0;
}
What do you mean?
do you mean something like:

1
2
3
4
5
6
7
int main ()
{
    do {

        /* your code */

    } while ( condition );


it may be better if you say what lines you would like to loop
Hi there,

A common way to loop a menu is something like the following:

1
2
3
4
5
6
int choice;

do
{
    //all your menu stuff
} while (choice > 0);


This will show your menu at least once, then it will check if the choice entered was higher than zero. If it was, it repeats the loop, if it wasn't it breaks out of the loop.

Hope that helps. Please do let us know if you have any further questions.

All the best,
NwN
Topic archived. No new replies allowed.