-2

I'm new to functions and I can't seem to figure out how to make a variable in a function return as a variable in main();

When I do:

int menu()
{
cin >> select;
return (select);
}

int main()
{
int x = menu;
return 0;
}

I get "invalid conversion from 'int (*)()' to 'int' [-fpermissive]

This code has also been very simplified but that's the idea, how do I get this variable to equal the value that my function has returned?

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
user2945132
  • 11
  • 1
  • 2

1 Answers1

2
int menu()   
{
   int select;
   cin >> select;
   return select;
}

int main()
{
   int x = menu();
   return 0;
}
  1. Declare select before using it.
  2. Add () to the call to menu.
  3. (optional) remove the unnecessary parentheses around select in the return statement.
JBentley
  • 6,099
  • 5
  • 37
  • 72
Germán Diago
  • 7,473
  • 1
  • 36
  • 59