Need help with a hw question that involves structs and functions

to keep things simple the question asks me to read a menu for restaurant from a file, have the user place an order and then print out a check. The problem for me arises during the print check function where i have to display the item ordered and have it calculate the price of all the items and the total, i keep getting a run time error. Any help is appreciated as im out of ideas (i've removed the header function for privacy reasons).

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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;

struct menuItemType
{
	string menuItem;
	double menuPrice;

};

void header();
void getdata(ifstream&, menuItemType menuList[]);
void showmenu(ifstream&, menuItemType menuList[]);
void order(ifstream&, menuItemType menuList[], int amount[], int choice[], int&, int&);
void printcheck(ifstream&, menuItemType menuList[], int amount[], int choice[], int&, int&);

int main()
{
	ifstream in;
	in.open("menu.txt");
	int amount[1000];
	int choice[1000];
	int i = 0;
	int j = 0;

	cout << fixed << setprecision(2);

	header();

	menuItemType menuList[8];
	getdata(in, menuList);
	showmenu(in, menuList);
	order(in, menuList, amount, choice, i, j);
	printcheck(in, menuList, amount, choice, i, j);










	return 0;
}
void getdata(ifstream& in, menuItemType menuList[])
{
	while (!in.eof())
	{
		for (int i = 0; i < 8; i++)
		{
			getline(in, menuList[i].menuItem, '$');
			in >> menuList[i].menuPrice;
			in.ignore(50, '\n');
		}
			
	}


}
void showmenu(ifstream& in, menuItemType menuList[])
{
	cout << "\t\t\t Welcome to Johnny's Restaurant" << endl;
	cout << "\t\t\t\t\t MENU" << endl;
	cout << endl;

	for (int i = 1; i <= 7; i++)
	{
		cout << i << "." << setw(10) << right << menuList[i].menuItem
			<< setw(20) << right << "$" << menuList[i].menuPrice << endl;

	}



}

void order(ifstream& in, menuItemType menuList[], int amount[], int choice[], int& i, int& j)
{
	bool flag = true;
	char cont = char();

	while (flag)
	{
		cout << "Please enter the number of the order: ";
		cin >> choice[i];

		while (choice[i] <= 0 || choice[i] > 7)
		{
			cout << "Please input valid order number: ";
			cin >> choice[i];

			if (cin.fail())
			{
				cin.clear();
				cin.ignore(1000, '\n');
				cin >> choice[i];

			}

		}

		cout << endl << "Please enter the amount of " << menuList[choice[i]].menuItem << "that you want: ";
		cin >> amount[j];

		while (amount[j] <= 0 || amount[j] > 1000)
		{
			cout << "Please input valid amount: ";
			cin >> amount[j];

			if (cin.fail())
			{
				cin.clear();
				cin.ignore(1000, '\n');
				cin >> amount[j];

			}

		}


		cout << endl << "Do you wish to continue ordering? Y/N" << endl;
		cin >> cont;

		if (cont == 'y' || cont == 'Y')
		{
			flag = true;
			i++;
			j++;
			if (i == 8 && j == 8)
				break;

		}
		else
		{
			flag = false;

		}


	}


}

void printcheck(ifstream& in, menuItemType menuList[], int amount[], int choice[], int& i, int& j)
{
	const double tax = .09;
	double total = 0;
	double price = double();
	bool flag = true;

	system("cls");
	cout << "\t\t\t\t\t Check" << endl;
	cout << endl;

	

	for (i = 0; i <= 8; i++)
	{
		cout << menuList[choice[i]].menuItem;
		price = menuList[choice[i]].menuPrice * amount[j];
		cout << price << endl;
	}
	

	for (int k = 0; k < 80; k++)
	{
		cout << "_";

	}

	total += price;
	cout << endl << "Total" << total << endl;

}
uhmm i think you didnt implement the function

 
void header();


not that am saying that's the problem, just thought i should point it out!
yeah i took the function because it had information i didnt want people to see such as my real name, school im in, etc. I just forgot to take the function out in the main. Thanks though! =P
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
void printcheck(ifstream& in, menuItemType menuList[], int amount[], int choice[], int& i, int& j)
{
	const double tax = .09;
	double total = 0;
	double price = double();
	bool flag = true;

	system("cls");
	cout << "\t\t\t\t\t Check" << endl;
	cout << endl;



	for (unsigned var = 0; var <= i && var <= j; var++)
	{
		cout << menuList[choice[var]].menuItem;
		price = menuList[choice[var]].menuPrice * amount[var];
		cout << price << endl;
        total += price;
	}


	for (int k = 0; k < 80; k++)
	{
		cout << "_";

	}


	cout << endl << "Total " << total << endl;

}
Thanks Yanson, that worked. :D
Topic archived. No new replies allowed.