First I want to say thanks to all the people that helped before! I have a new problem. I am creating a text based point of sales system. The code I have so far compiles okay but the struct is messed up. I have input that I think I did right but when its printed back out it's all garbage. please help!! thanks!
You need to look up what "scopes of variables" are. When you modify breakfastMenu inside of getData(), you are modifying a local variable with that name, completely separate from the one in main(). The same with your other functions.
Wow two things. First thanks for the super fast response and okay... missed that one cool thanks lol. So I removed the struct's form the definitions but I still get errors I have included the updated code and the errors I get.
I get 2 errors both the same one in 78 and the other in 101 (marked in the code)
"error 'breakfastMenu' was not declared in this scope". PLEASE HELP
1) Your function definitions (at the bottom), are slightly incorrect. You haven't named what the variable you are passing in is called, so you can't use it in the function.
2) Your functions are only accepting a *single* menuItemType variable, not an entire array. I would suggest turning the array into a vector since it is easier to pass than an array.
3) Your getData function will make a copy of the variable passed to it, which means the changes you make in the function don't actually affect the variable you are passing in. Pass the variable by reference if you want to change it.
1 2 3 4
//example:
void change_int_to_two(int& the_int) {//note the '&'
the_int = 2; //since we pass by reference, this actually modifies what is passed
}
kk I made some changes and now when I try and compile it I get the following two errors:
error: line 29: undefined reference to 'getData(menuItemType)'
error: line 36: undefined reference to 'showmenu(menuItemType)'
woot thanks for the fast response and I did make the vector change, don't know why I didn't catch that one earlier. as far as the declarations what changes do I need to make? I am really confused and a little overwhelmed. do I simply need to make them look like the definitions?? if not could someone please post an example.
Yes, when you make the call you should just pass breakfastMenu. The type of breakfastMenu is menuItemType[8]. The compiler already knows that, you told him in the declarations/definitions of your functions. What you simply have to do now is:
getData (breakfastMenu);
showMenu (breakfastMenu);
EDIT: breakfastMenu[8] actually is the 9th element of your array (the element past the 8th element) and its type is menuItemType, not what your functions expect. In fact, your functions expect menuItemType* and breakfastMenu is silently converted from menuItemType[8] to menuItemType* when you pass it.