Hello helena97,
Welcome to the forum.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
To start with it is "<iostream>" for C++ there is no such file as "<iostream.h>".
Line 9. Is OK, but I would try to avoid using a non "const" global variable.
Line 12. Is generally written as
int main()
with a
return 0;
just before the closing brace of main.
Starting at line 26 the do/while loop will work once. The condition
while (0)
is the same as saying
while (false)
which means it will not loop back to the top. "case 4:" no one but you know it is available. You should not use "exit(1)" the 1 or higher number generally means that there is a problem. I find this bit of code to work well with a do/while loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
int main()
{
int choice{};
bool cont{ true };
do
{
switch (choice)
{
case 1:
break;
case 2:
break;
case 4: // the exit number
cont = false;
break;
}
} while (cont);
return 0;
}
|
In the menu function, which I have no spent much time on the while condition
while (4)
again is the same as
while (true)
which is an endless loop. And you have the same problem with "case 4:" as I mentioned earlier.
For the order function it starts out OK, but falls apart at about line 139 after you print out the headings. You should print what you have entered earlier not ask for new input that you already have. At the beginning of the function you prompt for the "food_code", but not for the "quantity". this leaves the user wondering what to input. At about line 139 the "std::cin" statements would be replaced with "std::cout" statements to print what you have entered.
You have left out the line
using namespace std;
which is good. You should avoid using this line, but you will need to qualify what is in the "std" name space like: "std::cin", "std::cout", "std::endl" and others. it is better to start learning what is in the "std" name space now rather than later.
Also understand that generally C++ header files have no extension and a header file with a ".h" extension is an old C header and that some of these header files are not available with newer compilers. The "<stdlib.h>" is included through the "<iostream>" header file, so you do not always need to include this file.
Hope that helps,
Andy