Strange function problem!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <windows.h>
using namespace std;

void about(){
		cout<<"Expence-List 14/10/2008:"<<endl
		      <<"Brought to you by www.******.com"<<endl
    		      <<"Programmed by **********."<<endl;
		Sleep(4000);
		system("cls");
	}


int MenuOne(){
		int MenuSelection=0;
		cout<<"What would you like to do?"<<endl
			<<"--------------------------------"<<endl
			<<"1. Create a new expence list."<<endl
			<<"2. Edit a previous expence list."<<endl
			<<"3. View a saved expence list."<<endl
			<<"4. Settings"<<endl
			<<"5. About."<<endl
			<<"6. Close Program"<<endl
			<<"--------------------------------"<<endl
			<<endl;
		cin>>MenuSelection;
		system("cls");
		return MenuSelection;
	}
	

int MenuProcessing(int MenuSize,int MenuSelection){
		int b=1;
		if(MenuSelection>MenuSize){
			cerr<<"You've entered an invalid option!"<<endl
				<<"Try again!."<<endl;
			Sleep(2000);
			system("cls");
			return 0;
		}

		while(MenuSize>b){
			if(MenuSelection=b){
			}

			}

			b++;
		}


int main(){
	start:
	int MenuSelection=0,EventStatis;
	about();
	MenuSelection=MenuOne();
	EventStatis=MenuProcessing(6,MenuSelection);
	if(EventStatis=0){
		goto start;
	}
    return 0;
}


so thats my code right.
where it says the function menuprocessing. I need a menuprocessing thingo cause i using lots and lots of menus.
so what i want is for where the

1
2
3
4
5
		while(MenuSize>b){
			if(MenuSelection=b){
			}

			}

is i want it to send it to the approbate selected menu thing.
so something like a function array....

1
2
void MenuOne[1](){
}


so when MenuMelection=b it would go to the MenuOne[b]();

sucks that function arrays don't exist.

how would i go about doing something like that?
Last edited on
Bump. :]
umm sorry bout bump i need answer pretty urgent cause i have to go soon.
You could make an array of pointers to the functions you want I guess...Use the search function, I think this was answered a couple days ago.
I found that here just the other day -- it's why I signed up. It is possible to make an array of pointers to functions. I think I found it searching for "function pointers".
i need a function to be able to run another function.
but the name of the function is dependant on what number you entered in the menu.
but it can work with any menu.

what do i search lol.
You cannot call a function based on a string literal or string variable, but you could put the pointers to functions into an array and call the number of the array based on the number of the menu.
I think I would drop the function pointers idea, and go with a switch statement instead of:

while(MenuSize>b){
if(MenuSelection=b){
}

}

b++;
}

but hey, I'm a beginner too.

PS. check the difference of "=" and "==".
Last edited on
Topic archived. No new replies allowed.