Struct and Arrays, menu driven

I'm working with structs and arrays, and I was wondering how I could get the function "makeselection" to work, I'm stumped on it, I know it's wrong but I'm looking for a way around it. I'm not sure what parameters to use, or how to access the information in the struct

The assignment is making a resturant menu and printing out a check with tax, it also calls for it to be ran multiple times. I can't delete the functions I have because the assignment requires those. Advice?

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

//VARIABLES!!
int menulist[8]; 
int itemselect = 0; 
int quantity = 0;
double total = 0;
const double tax = .05;
struct menuItemType
{
	string menuItem;
	double menuPrice; 
};

//PROTOTYPES!!!
void showMenu();
void data2array(menuItemType menuList[8]);
void makeselection(int itemselect, int quantity, menuItemType menuList[8]);
void printcheck();

//FUNCTIONS!!!
void showMenu() //Function shows menu of items offered by restaurant
{
	cout << "Welcome to Johnny's Restaurant!!" << endl;
	cout << endl;
	cout << "Menu: " << endl;
	cout << endl;
	cout << "1.) Plain Egg" << "	        $1.45" << endl;
	cout << "2.) Bacon and Egg" << "	$2.45" << endl;
	cout << "3.) Muffin" << "		$0.99" << endl;
	cout << "4.) French Toast" << "	$1.99" << endl;
	cout << "5.) Fruit Basket" << "	$2.49" << endl;
	cout << "6.) Cereal" << "		$0.69" << endl;
	cout << "7.) Coffee" << "		$0.50" << endl;
	cout << "8.) Tea" << "			$0.75" << endl;

	cout << endl;
	cout << endl;
	cout << "How to use this program: " << endl;
	cout << "To make a selection, simply type the number of the item you want to choose!" << endl;
	cout << "Ex: for a plain egg, press 1" << endl;
	cout << "Then type the quantity that you want of this item." << endl;
	cout << endl;
	cout << endl;

}

void data2array(menuItemType menuList[8])
{
	menuList[0].menuItem = "Plain Egg";
	menuList[1].menuItem = "Bacon and Egg"; 
	menuList[2].menuItem = "Muffin";
	menuList[3].menuItem = "French Toast";
	menuList[4].menuItem = "Fruit Basket";
	menuList[5].menuItem = "Cereal";
	menuList[6].menuItem = "Coffee";
	menuList[7].menuItem = "Tea";

	menuList[0].menuPrice = 1.45;
	menuList[1].menuPrice = 2.45;
	menuList[2].menuPrice = 0.99;
	menuList[3].menuPrice = 1.99;
	menuList[4].menuPrice = 2.49;
	menuList[5].menuPrice = 0.69;
	menuList[6].menuPrice = 0.50;
	menuList[7].menuPrice = 0.75;

}

void makeselection(int itemselect, int quantity, menuItemType menuList[8])
{
	bool order = true;
	int x = 0; 

	while (order)
	{
		cout << endl;
		cout << "Please enter what item you would like!" << endl;
		cout << "Type 0 to complete your order." << endl;
		cout << endl;
		cin >> itemselect;
		x = itemselect; 
 
		menuList[x]; 

		if (itemselect != 0)
		{
			menuList[x];
			menuList.menuPrice;
			cout << "How many of this item would you like?" << endl;
			cin >> quantity;
		}

		else
		{
			order = false; 
		}
	}

}

void printcheck()
{

}



int main()
{
	//call function to show menu
	showMenu();

	//Create an array of for the struct
	menuItemType menuList[8]; 

	//call function to load our data into an array
	data2array(menuList);

	//make selection
	makeselection(itemselect, quantity, menuList);

	//print out check
	printcheck();

	system("pause");
	return 0; 
}
In line no. 7, you hav given menulist an int type of variable.
int menulist[8];

But in void data2array(...) you hav used menulist of type menuItem.
I suggest you give menulist of the type menuItem(struct) to make your program work.
In func void makeselection(...) , I suggest you change void to double and do something like this :

1
2
3
4
5
6
7
8
double result;
bool order =true; 
int count = 0;
//loop through the code
cin>>count;
result = ( menuItem.menuPrice * count) * tax;
//end loop
return result;

Topic archived. No new replies allowed.