Reputation: 63
I have a menu when i select 2 variables and then i must choose between a man and a woman. After that i must go to man.c or woman.c with the 2 variables previously choosed but i dont know how can i do that.
my main.c (only when the man option in the menu):
printf("Insert weight: ");
scanf("%f",&a);
printf("Insert high: ");
scanf("%f",&b);
switch(opcion){
case 'm':;
--here i want to go to man.c to continue with other menu but knowing variables weight and high--
man.c and woman.c are similars the ionly difference is when calculates the body mass index
man.c :
int bmi(float weight, float high){
float bmi;
char opcion;
printf("a) Calculate body mass index");
switch(opcion){
case 'a': bmi = weight / high;
break;
}
}
now i ave only this and woman is the same. When is finished man.c and woman.c will have 4 options using weigh, high and some variables more that they asked when needed with scanf.
Upvotes: 0
Views: 295
Reputation: 676
General:
Solution.
Add two functions void handleMan(float weight ,float height);
and void handleWoman(float weight ,float height);
prototypes to main.c (just copy code before menu()
or main()
and implement them in man.c and woman.c later on call right method upon user selection.
Upvotes: 1
Reputation: 725
Well you have to define procedures for man and woman and call procedure in switch statement and perform your individual activities in the respective methods .
Upvotes: 0
Reputation: 28137
1) You can't simply navigate through c files in C.
2) You can do that using includes & classes, but it's a bit hard for a beginner
3) The right way to do it is something like this:
printf("M/F");
scanf("%f",&option);
switch(option){
case M:
do_man();
break;
case F:
do_woman();
break;
}
And you should declare the functions do_man() and do_woman() before the main.
Upvotes: 1
Reputation: 325
The easiest way would be to call a gender specific function in the switch. For example man_menu() and woman_menu(). These could also be located in different .c files but then you need to link the object files together.
Upvotes: 0
Reputation: 49344
I'd suggest you call a function (say manMenu()
) and keep it in same .c file.
Upvotes: 1