Hi!

I have 5 different functions which all must be connected to main, for example a menu that calls each function. How do I do this?

Thanks in advance!

Best regards
Adam

in main(), do as following:

int choice = menu();/*implement menu. It should returns the user choice*/
switch(choice)
{
   case 1:
          fun1();/*your fun*/
          break;
   case 2:
          fun2();/*your fun*/
          break;
    /*some more cases as required*/
   default:
         /*some error message*/
}

Hi again!

Thanks, I am going to try this at once!

One more question is, if my fifth function must returns a value in main, how would I do this? For example a sum from two numbers?

Thanks in advance!

Best regards
Adam

Edited 6 Years Ago by foxmulder: n/a

case 1:
	int newValue == fun2(number1, number2);
	break;

Edited 6 Years Ago by kevinkace: n/a

it's similar to using multiple if/else statements but is more efficient when the value you are checking has only one option, ie making a selection from a menu.

Check this

// Enumeration for menu selection
enum Menu {
	ADDTOEND = '1',
	ADDTOSTART = '2',
	ADDSPECIFIC = '3',
	REMOVESPECIFIC = '4',
	PRINTLIST = '5',
	QUIT = '9',
};


int menuSelection = 0;

	while(menuSelection != QUIT)
	{
		menuSelection = SelectMenuChoice();


		switch(menuSelection)
		{
		case ADDTOEND:
			AddToEnd(userList);
			break;
		case ADDTOSTART:
			AddToStart(userList);
			break;
		case ADDSPECIFIC:
			AddSpecific(userList);
			break;
		case REMOVESPECIFIC:
			if(userList->head != 0)
			{ RemoveSpecific(userList); }
			else
			{ cout << "No nodes to delete" << endl; }
			break;
		case PRINTLIST:
			PrintList(userList);
			break;
		default:
			break;

		}
	}

Edited 6 Years Ago by kevinkace: n/a

This article has been dead for over six months. Start a new discussion instead.