Weekly Food Menu Program

I'm trying write a program to make a weekly meal plan. I have a list of major food groups (chicken, turkey, beef, pork, fish, veggie, other) and then another menu of side dishes to add to the meal (carrots, greenbeans, broccoli, okra, spinach). I don't want to repeat a meal item. Another catch, some nights my son is with me and he HATES okra. So, on those nights I have to nix that option. So once I've selected a main and side option, I want to be able to print out a weekly meal menu.

So far I have this:
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
#include <iostream>
using namespace std;
int meat_menu()		// function prototype
int side_menu()		// function prototype

void main()
{
	// variables
	int meat, side, i=0;
	double meat [7] = {chicken, turkey, beef, pork, fish, veggie, other};
	double option [5]= {carrots, greenbeans, broccoli, okra, spinach};
	int OptYN [5]={0,0,0,0,0};

	model=meat_menu();	// call menu function
	while (meat !=0)
	{
		switch (model)
		{
			case (1):		// Chicken
				meat = meat[0];
			case (2):		// Turkey
				meat = meat[1];
			case (3):		// Beef
				meat = meat[2];
			case (4):		// Pork
   				meat = meat[3];
                        case (5):               // Fish
                                meat = meat[4]; 
                        case (6):               // Veggie
                                meat = meat[5]; 
                        case (7):               // Other
                                meat = meat[6];
			case (0):		// quit
			exit(1);
			default:
				cout<< "\nPlease enter a correct menu choice." << endl;
		}
		meat=meat_menu();		// call menu function
	
		side=side_menu();	// call option function	
		while (side !=0)
		{
			switch (side)
			{
				case (1):		// Carrots
					side_dish = option[0];
				case (2):		// Green Beans
					side_dish= option[1];
				case (3):		// Broccoli
                                        side_dish = option[2]
				case (4):		// Okra
					
}

Now I know this is incomplete, but I want to be sure I'm on the right track.

For the option selection bit I have this bit.

1
2
3
4
5
6
7
8
9
int var,i=0,meat[7]={0};
meat_menu[7]={0}; 
/*
  gather value for menu option to meat
*/
meat[meat]=1;
for(i=0;i<7;i++) {
  if(meat_menu[i]==0) printf("Menu item %d is not selected\n",i);
}


Is this about right?
If not, what do I need to do to make this work?
1) it should be int main() not void main

2) You have two variables named 'meat'. This is a name conflict. Which 'meat' do you expect the compiler to use and where? Name them something different.

3) Your prototypes are missing semicolons.

4) Why would you be using printf if you're using cout? why not just use cout? Not that big of an issue, it's just a consistency thing.

5) I don't know what carrots, turkey, beef, etc are, but they're sure not doubles. You probalby meant to make them strings, in which case you should have arrays of strings (not doubles) and you should be putting them in quotes. ie: "turkey", "beef", etc.

6) You need to put breaks in your cases (in your switches). Remember that program flow doesn't exit the switch when it comes to a case label, so unless you put in breaks, if something runs the first case label it will run ALL the case labels.

7) You don't really even need a switch anyway. The whole point of having a lookup table like you have is to avoid that mess. Instead of having a case for every possible selection, do something like this:
1
2
if(number_is_in_range)
    side_dish = option[number - 1];


8) A lot of these errors would be exposed if you actually tried to compile this code. You really should be compiling FREQUENTLY and fix errors right away. I get the impression you're just writing tons of code and never compiling to see if any of it is valid... which leaves you with what you posted: a bunch of code that is almost C++ but is full of errors.

9) There's probably more, but I'm stopping for now.
Last edited on
Topic archived. No new replies allowed.