The following program allows a user to select a nursery rhyme from a menu. My task is to incorporate sub-menus (nursery rhyme and fairy tales) into the program. I've tried to do this but with no success as you can see below this program. Any help with this would be greatly appreciated.
If anyone has a non-related menu program i could have a look at as a guide to help me learn how to do this, i would be greatful.
I use Dev-C++
programming in C
[code]
#include<stdio.h>
#include<stdlib.h>
/* Prototype */
int f_menu();
void f_mary ();
void f_jack ();
void f_bopeep ();
int main (void)
{
int choice_d;
do
{
choice_d = f_menu ();
switch (choice_d)
{
case 1: f_mary ();
break;
case 2: f_jack ();
break;
case 3: f_bopeep ();
break;
case 4: printf ("Bye Bye\n\n");
break;
}
}
while (choice_d != 4);
system ("Pause");
return 0;
}
/* ************************************************** ******************* */
int f_menu ()
{
int select_d;
do
{
printf ("This is a nursery rhyme program\n");
printf ("You can choose to display three different nursery rhymes\n\n");
printf ("(1) Mary had a little lamb\n(2) Jack and Jill\n(3) Little Bo Peep\n(4) Quit\n\n");
printf ("Enter a number that corresponds to your choice > ");
scanf ("%d", &select_d);
printf("\n");
if (( select_d < 1 ) || ( select_d > 4));
printf("You have entered an invalid choice. Please try again\n\n\n");
}
while (( select_d < 1) || ( select_d > 4));
return select_d;
}
/* ************************************************** ************************** */
void f_mary ()
{
printf("Mary had a little lamb\n fleese white as snow\n\n\n");
}
/* ************************************************** ************************** */
void f_jack ()
{
printf("Jack and jill went up the hill to fetch water\nThen they fell down\n\n\n");
}
/* ************************************************** ************************** */
void f_bopeep ()
{
printf("Little bo peep had sheep\nthen they came home\n\n\n");
}
[code]
My Attempt
[code]
#include<stdio.h>
#include<stdlib.h>
/* Prototype */
int f_menu();
int f_rhymemenu();
int f_rhymemenu2();
int f_fairymenu();
int f_fairymenu2();
int main (void)
{
int choice_d;
do
{
choice_d = f_menu ();
switch (choice_d)
{
case 1: f_rhymemenu ();
break;
case 2: f_fairymenu ();
break;
case 3: printf ("Bye Bye\n\n");
break;
}
}
while (choice_d != 3);
system ("Pause");
return 0;
}
/* ************************************************** ******************* */
int f_menu ()
{
int select_d;
do
{
printf ("This is a nursery rhyme and fairy stories program\n");
printf ("You can choose to display a number of different nursery rhymes and fairy stories\n\n");
printf ("(1) Nursery rhymes\n(2) Fairy stories\n(3) Quit\n\n");
printf ("Enter a number that corresponds to your choice > ");
scanf ("%d", &select_d);
printf("\n");
if (( select_d < 1 ) || ( select_d > 3));
printf("You have entered an invalid choice. Please try again\n\n\n");
}
while (( select_d < 1) || ( select_d > 3));
return select_d;
}
/* ************************************************** ************************** */
int f_rhymemenu ()
{
int f_rhymemenu2();
int choicerhyme_d;
void f_mary ();
void f_jack ();
void f_bopeep ();
do
{
choicerhyme_d = f_rhymemenu2();
switch (choicerhyme_d)
{
case 1: f_mary ();
break;
case 2: f_jack ();
break;
case 3: f_bopeep ();
break;
case 4: printf ("Bye Bye\n\n");
break;
}
}
while (choicerhyme_d != 4);
}
/* ************************************************** ******************* */
int rhymemenu2()
{
int select_d;
do
{
printf ("(1) Mary had a little lamb\n(2) Jack and Jill\n(3) Little Bo Peep\n(4) Quit\n\n");
printf ("Enter a number that corresponds to your choice > ");
scanf ("%d", &select_d);
printf("\n");
if (( select_d < 1 ) || ( select_d > 4));
printf("You have entered an invalid choice. Please try again\n\n\n");
}
while (( select_d < 1) || ( select_d > 4));
return select_d;
}
/* ************************************************** ************************** */
int f_fairymenu ()
{
int choicefairy_d;
void f_zub();
void f_bfg();
void f_aliens();
do
{
choicefairy_d = f_fairymenu2 ();
switch (choicefairy_d)
{
case 1: f_zub ();
break;
case 2: f_bfg ();
break;
case 3: f_aliens ();
break;
case 4: printf ("Bye Bye\n\n");
break;
}
}
while (choicefairy_d != 4);
}
/* ************************************************** ******************* */
int f_fairymenu2 ()
{
int select_d;
do
{
printf ("(1) The zub zubs\n(2) The BFG\n(3) Aliens\n(4) Quit\n\n");
printf ("Enter a number that corresponds to your choice > ");
scanf ("%d", &select_d);
printf("\n");
if (( select_d < 1 ) || ( select_d > 4));
printf("You have entered an invalid choice. Please try again\n\n\n");
}
while (( select_d < 1) || ( select_d > 4));
return select_d;
}
/* ************************************************** ************************** */
void f_mary ()
{
printf("Mary had a little lamb\n fleese white as snow\n\n\n");
}
/* ************************************************** ************************** */
void f_jack ()
{
printf("Jack and jill went up the hill to fetch water\nThen they fell down\n\n\n");
}
/* ************************************************** ************************** */
void f_bopeep ()
{
printf("Little bo peep had sheep\nthen they came home\n\n\n");
}
/* ************************************************** ************************** */
void f_zub ()
{
printf("zub zub zub zub zub zub zub zub\n\n\n");
}
/* ************************************************** ************************** */
void f_bfg ()
{
printf("im big and fat and a git\n\n\n");
}
/* ************************************************** ************************** */
void f_aliens ()
{
printf("take us to your leader\n\n\n");
}
[code]