#include<iostream>
#include<string>
#include <iomanip>
using namespace std;
int menu(int choice);
int main()
{
menu(choice);
do
{
switch(choice)
{
case 1:
cout<<"welcome to 1";
break;
case 2:
cout<<"welcome to 2";
break;
case 3:
cout<<"The program will end";
break;
}
}while(choice !=3);
return 0;
}
int menu(int choice) //void function that displays the menu, ask users
{ //to input their choice, then reference the choice to the main function.
cout<<"first option "<<endl;
cout<<"second option"<<endl;
cout<<"third option "<<endl;
cout<<"Your choose option: ";
cin>>choice;
return choice;
}
The problem is the line "menu(choice) " tells me it is not declared, but it is in my function.
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 add to what Thoas165 said the function "menu" returns an int so you will need a variable to capture the return value or pass "choice" by reference, i.e., int menu(int& choice). this will allow you to change the value of "choice in main. Or you would need to call "menu" with choice = menu(choice). Either way you would need to define "choice" in main before you use it.
I add int choice=0; before the menu(choice).
Now my program can run, but it stops at the switch.
When I input 1,2,or 3 ,and then enter , the program just stops.