Getting an error C2059

Write your question here.

I was doing this for a homework problem for class and keep running into this error.

Here was the problem:

Write a program to help a local restaurant automate its billing system. The program should do the following:

-Show the customer the different items offered by the restaurant
-Allow the customer to select more than one item from the menu
-Calculate and print the bill

Required:

Use an array menuList from a struct defined as menuItemType (string menuItem double itemPrice)

- a function to load the data into the array
- a function to show the items and tell the user how to select them
- A function to show the bill

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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

struct menuItemType															//defining the struct menuItemType
{
	string menuItem;
	double menuPrice;
};

struct orderType															//defining struct orderType
{
	string menuItem;
	double itemPrice;
};

const double TAX = .05;

void menuShow(menuItemType menuList[], orderType orderList[], int count, int select, int in);
void getData(menuItemType menuList[], int c);
void printBill(orderType orderList[], int orderCount, const double TAX);

ifstream inData;

int main()
{

	inData.open("Menu.txt");

	menuItemType menuList[8];																									//Array menuList for struct menuType
	orderType orderList[8];																										//Array orderList for struct orderType

	int in = 0;																													//for the choice inputs
	int orderCount = 0;
	int count = 0;
	int select = ' ';

	getData(menuList[], int c);																					//check on the text input
	
	menuShow(menuList[], orderList[], int count, int select, int select);											//calling the funciton for the menu and order process

	printBill(orderList[], int orderCount, const double TAX);													//calling the function for the check											
	

	system("pause");

}

void menuShow(menuItemType menuList[], orderType orderList[], int count, int select, int c)
{
	cout << fixed << showpoint << setprecision(2);																					//setting it to show to 2 decimal places

	cout << "Welcome to John's Breakfasts!\n";

	for (c = 0; c < 8; c++)
	{
		cout << c + 1 << menuList[c].menuItem << "			" << menuList[c].menuPrice << endl;
	}

	do																																//do-while loop
	{
		cout << "Enter a selection of 1-8 for your order and press 9 when finished: \n";
		cin >> select;

		switch (select)																												//swtich statement for the selections
		{
		case 1:
			cout << menuList[0].menuItem << "	" << menuList[0].menuPrice << endl;
			break;
		case 2:
			cout << menuList[1].menuItem << "	" << menuList[1].menuPrice << endl;
			break;
		case 3:
			cout << menuList[2].menuItem << "	" << menuList[2].menuPrice << endl;
			break;
		case 4:
			cout << menuList[3].menuItem << "	" << menuList[3].menuPrice << endl;
			break;
		case 5:
			cout << menuList[4].menuItem << "	" << menuList[4].menuPrice << endl;
			break;
		case 6:
			cout << menuList[5].menuItem << "	" << menuList[5].menuPrice << endl;
			break;
		case 7:
			cout << menuList[6].menuItem << "	" << menuList[7].menuPrice << endl;
			break;
		case 8:
			cout << menuList[7].menuItem << "	" << menuList[9].menuPrice << endl;
			break;
		case 9:
			cout << "Calculating price.\n";
			break;
		default:
			cout << "Invalid selection\n";
		}																										//end of switch statement
	} while (select != 9);																						//while condition for do-while loop
	
	if (select > 0 && select <= 8)
	{
		orderList[select].menuItem = menuList[select - 1].menuItem;
		orderList[select].itemPrice = menuList[select - 1].menuPrice;
		count++;
	}
	else if (select == 9)
	{
		cout << "Done.\n";
	}
}

void getData(menuItemType menuList[], int c)
{
	while (!inData.eof())
	{
	inData >> menuList[c].menuItem >> menuList[c].menuPrice;
	c++;
	}

}

void printBill(orderType orderList[], int orderCount, const double TAX)
{
	cout << "Here is a list of the items you purchased: " << endl;

	for (int orderCount = 0; orderCount < 8; orderCount++)
	{
		cout << orderList[orderCount].menuItem << " " << orderList[orderCount].itemPrice << endl;
	}

}


What I had in the input file:

Plain Egg 1.45
Bacon and Egg 2.45
Muffin 0.99
French Toast 1.99
Fruit Basket 2.49
Cereal 0.69
Coffee 0.50
Tea 0.75


Really want this to be sorted out before I work on addressing other bits that may be missing.
I was doing this for a homework problem for class and keep running into this error.

When you receive an error or warning, please post the complete error or warning message as well. These messages have important information embedded within them to aid locating and fixing the problems.

Oh, sorry.

It's Error C2509: syntax error: ']'
That's not the complete error message. There should also be a line number where the error was detected.

And note you should probably have multiple error/warning messages, here is what my compiler reports:
main.cpp||In constructor ‘menuItemType::menuItemType()’:|
main.cpp|8|warning: ‘menuItemType::menuItem’ should be initialized in the member initialization list [-Weffc++]|
main.cpp|8|warning: ‘menuItemType::menuPrice’ should be initialized in the member initialization list [-Weffc++]|
main.cpp||In function ‘int main()’:|
main.cpp|33|note: synthesized method ‘menuItemType::menuItemType()’ first required here |
main.cpp||In constructor ‘orderType::orderType()’:|
main.cpp|14|warning: ‘orderType::menuItem’ should be initialized in the member initialization list [-Weffc++]|
main.cpp|14|warning: ‘orderType::itemPrice’ should be initialized in the member initialization list [-Weffc++]|
main.cpp||In function ‘int main()’:|
main.cpp|34|note: synthesized method ‘orderType::orderType()’ first required here |
main.cpp|41|error: expected primary-expression before ‘]’ token|
main.cpp|41|error: expected primary-expression before ‘int’|
main.cpp|43|error: expected primary-expression before ‘]’ token|
main.cpp|43|error: expected primary-expression before ‘]’ token|
main.cpp|43|error: expected primary-expression before ‘int’|
main.cpp|43|error: expected primary-expression before ‘int’|
main.cpp|43|error: expected primary-expression before ‘int’|
main.cpp|45|error: expected primary-expression before ‘]’ token|
main.cpp|45|error: expected primary-expression before ‘int’|
main.cpp|45|error: expected primary-expression before ‘const’|
main.cpp|36|warning: unused variable ‘in’ [-Wunused-variable]|
main.cpp|37|warning: unused variable ‘orderCount’ [-Wunused-variable]|
main.cpp|38|warning: unused variable ‘count’ [-Wunused-variable]|
main.cpp|39|warning: unused variable ‘select’ [-Wunused-variable]|
main.cpp||In function ‘void printBill(orderType*, int, double)’:|
main.cpp|124|warning: declaration of ‘TAX’ shadows a global declaration [-Wshadow]|
main.cpp|20|warning: shadowed declaration is here [-Wshadow]|
main.cpp|128|warning: declaration of ‘int orderCount’ shadows a parameter [-Wshadow]|
main.cpp|124|warning: shadowed declaration is here [-Wshadow]|
main.cpp|124|warning: unused parameter ‘orderCount’ [-Wunused-parameter]|
main.cpp|124|warning: unused parameter ‘TAX’ [-Wunused-parameter]|
||=== Build finished: 10 errors, 14 warnings (0 minutes, 1 seconds) ===|


The error message you seem to be referring to is probably this line:
getData(menuList[], int c);
Is this supposed to be a function call or function prototype? In either case it is incorrect. A function prototype should have a return type and a function call should not have the brackets [] or types, looking more like:
getData(menuList, c);
Thanks, that actually helped. Noticed some other issues, but these are ones I have experienced before and can fix.
Topic archived. No new replies allowed.