using void functions for calculation.

i want to use a void fucntion called menuselction and use the selection that
this function make in my main or i want to use this selection to do other things.

i already create a function for the menu. but how can i use a void function to make take the selection from the user and use it in my main.

for example if the menu consits of 1.2.3.4
and the menu selection function will be

1
2
3
4
5
6
7
 void MakeSelection()
{
  while  (choice >=1&& choice<=4 )
   {
        cin >>choice.
   }
 }


then i want to use this choice in my program like if choice i 1 then do some calculations.
hope you understand what i mean..
please help.. thanks..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

void MakeSelection( int &choice )
{
   while  ( choice >=1 && choice <=4 )
   {
        std::cin >>choice.
   }
}

int main()
{
   int choice;

   MakeSelection( choice );

   std::cout << "You have chosen " << choice << std::endl;
}

wow!! thanks bro .. that's what i really want to know..
thanks very much for your help..
By the way variable choice should be initialized.:) So it is better to use the do-while loop instead of the while loop

1
2
3
4
5
6
7
void MakeSelection( int &choice )
{
   do
   {
        std::cin >>choice.
   } while  ( choice >=1 && choice <=4 );
}
Topic archived. No new replies allowed.