473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Creating Menus with Sub-menus

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]
Nov 21 '06 #1
1 15643
sivadhas2006
142 100+
Hi,

I did some small changes in your code to make it work.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. /* Prototype */
  5. int ShowMainMenu();
  6. int ShowRhymeMenu();
  7. int ShowRhymeSubMenu();
  8. int ShowFairyMenu();
  9. int ShowFairySubMenu();
  10.  
  11. void PrintZub();
  12. void PrintBigFatGit();
  13. void PrintAliens();
  14.  
  15. void PrintMary();
  16. void PrintJack();
  17. void PrintLittleBoPeep();
  18.  
  19. int main(void)
  20. {
  21.    int 
  22.       nChoice = 0;
  23.  
  24.    do
  25.    {
  26.       nChoice = ShowMainMenu ();
  27.       switch (nChoice)
  28.       {
  29.          case 1:
  30.          {
  31.             ShowRhymeMenu ();            
  32.          }
  33.          break;
  34.  
  35.          case 2: 
  36.          {
  37.             ShowFairyMenu ();
  38.          }
  39.          break;
  40.  
  41.          case 3: 
  42.          {
  43.             printf ("Bye Bye\n\n");
  44.          }
  45.          break;
  46.       }
  47.    }
  48.    while (nChoice != 3);
  49.    system ("Pause");
  50.    return 0;
  51.  
  52. /* ************************************************** ******************* */
  53.  
  54. int ShowMainMenu ()
  55. {
  56.    int 
  57.       nSelected = 0;
  58.  
  59.    do
  60.    {
  61.       printf ("This is a nursery rhyme and fairy stories program\n");
  62.       printf ("You can choose to display a number of different nursery rhymes and fairy stories\n\n");
  63.  
  64.       printf ("(1) Nursery rhymes\n(2) Fairy stories\n(3) Quit\n\n");
  65.  
  66.       printf ("Enter a number that corresponds to your choice > ");
  67.       scanf ("%d", &nSelected);
  68.       printf("\n");
  69.  
  70.       if (( nSelected < 1 ) || ( nSelected > 3))
  71.       {
  72.          printf("You have entered an invalid choice. Please try again\n\n\n");
  73.       }
  74.    }
  75.    while (( nSelected < 1) || ( nSelected > 3));
  76.  
  77.    return nSelected;
  78. }
  79.  
  80. /* ************************************************** ************************** */
  81. int ShowRhymeMenu ()
  82. {   
  83.    int 
  84.       nChoice = 0;   
  85.    do
  86.    {
  87.       nChoice = ShowRhymeSubMenu();
  88.       switch (nChoice)
  89.       {
  90.  
  91.          case 1:
  92.          {
  93.             PrintMary ();
  94.          }
  95.          break;
  96.  
  97.          case 2: 
  98.          {
  99.             PrintJack ();
  100.          }
  101.          break;
  102.  
  103.          case 3: 
  104.          {
  105.             PrintLittleBoPeep ();
  106.          }
  107.          break;
  108.  
  109.          case 4: 
  110.          {
  111.             printf ("Bye Bye\n\n");
  112.          }
  113.          break;
  114.       }
  115.    }
  116.    while (nChoice != 4);
  117.  
  118.    return nChoice;
  119. }
  120.  
  121. /* ************************************************** ******************* */
  122. int ShowRhymeSubMenu() 
  123. {
  124.    int 
  125.       nSelected = 0;
  126.  
  127.    do
  128.    {
  129.  
  130.       printf ("(1) Mary had a little lamb\n(2) Jack and Jill\n(3) Little Bo Peep\n(4) Quit\n\n");
  131.  
  132.       printf ("Enter a number that corresponds to your choice > ");
  133.       scanf ("%d", &nSelected);
  134.       printf("\n");
  135.  
  136.       if (( nSelected < 1 ) || ( nSelected > 4))
  137.       {
  138.          printf("You have entered an invalid choice. Please try again\n\n\n");
  139.       }
  140.    }
  141.    while (( nSelected < 1) || ( nSelected > 4));
  142.  
  143.    return nSelected;
  144. }
  145.  
  146. /* ************************************************** ************************** */
  147. int ShowFairyMenu ()
  148. {
  149.    int 
  150.       nChoice = 0;
  151.  
  152.    do
  153.    {
  154.       nChoice = ShowFairySubMenu ();
  155.       switch (nChoice)
  156.       {
  157.          case 1:
  158.          { 
  159.             PrintZub ();
  160.          }
  161.          break;
  162.  
  163.          case 2:
  164.          { 
  165.             PrintBigFatGit ();
  166.          }
  167.          break;
  168.  
  169.          case 3:          
  170.          {             
  171.             PrintAliens ();
  172.          }
  173.          break;
  174.  
  175.          case 4:
  176.          { 
  177.             printf ("Bye Bye\n\n");
  178.          }
  179.          break;
  180.       }
  181.    }
  182.    while (nChoice != 4);
  183.  
  184.    return nChoice;
  185. }
  186.  
  187. /* ************************************************** ******************* */
  188. int ShowFairySubMenu ()
  189. {
  190.    int 
  191.       nSelected = 0;
  192.  
  193.    do
  194.    {
  195.  
  196.       printf ("(1) The zub zubs\n(2) The BFG\n(3) PrintAliens\n(4) Quit\n\n");
  197.  
  198.       printf ("Enter a number that corresponds to your choice > ");
  199.       scanf ("%d", &nSelected);
  200.       printf("\n");
  201.  
  202.       if (( nSelected < 1 ) || ( nSelected > 4))
  203.       {
  204.          printf("You have entered an invalid choice. Please try again\n\n\n");
  205.       }
  206.    }
  207.    while (( nSelected < 1) || ( nSelected > 4));
  208.  
  209.    return nSelected;
  210. }
  211.  
  212. /* ************************************************** ************************** */
  213. void PrintMary ()
  214. {
  215.    printf("Mary had a little lamb\n fleese white as snow\n\n\n");
  216. }
  217.  
  218. /* ************************************************** ************************** */
  219. void PrintJack ()
  220. {
  221.    printf("Jack and jill went up the hill to fetch water\nThen they fell down\n\n\n");
  222. }
  223.  
  224. /* ************************************************** ************************** */
  225. void PrintLittleBoPeep()
  226. {
  227.    printf("Little bo peep had sheep\nthen they came home\n\n\n");
  228. }
  229.  
  230. /* ************************************************** ************************** */
  231. void PrintZub ()
  232. {
  233.    printf("zub zub zub zub zub zub zub zub\n\n\n");
  234. }
  235.  
  236. /* ************************************************** ************************** */
  237. void PrintBigFatGit ()
  238. {
  239.    printf("im big and fat and a git\n\n\n");
  240. }
  241. /* ************************************************** ************************** */
  242.  
  243. void PrintAliens ()
  244. {
  245.    printf("take us to your leader\n\n\n");
  246. }
  247.  
  248.  
Regards,
M.Sivadhas.
Nov 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
4
by: Coleen | last post by:
Hi All :-) Can anyone give me a URL where I can find a good example of code on how to create a temporary SQL table using VB.net? I've checked the Microsoft site at: ...
2
by: Val3 | last post by:
Hi all. I need to build dll(s) and windows services using VB .NET 2005 Express. When I make File/New project the windows contain only Windows application, Windows control library, Console...
1
by: Joel Whitehouse | last post by:
Hello All, I'm haveing a problem instantiating a form. When I try to instantiate my form and call it's ShowDialog() method, I get the following error message: An unhandled exception of type...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
1
by: bill | last post by:
I'm using VS2005. I am dynamically adding a Textbox control to a Placeholder control in the page_load event of the form, but the event handler isn't firing. What am I doing wrong? Thanks...
0
by: Lemune | last post by:
Hello everyone. I'm creating windows service application to capture data from my PABX, and send the data to sql server. My question is how could my application know when that PABX is sending data...
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
0
by: PracticalApps | last post by:
I looked to find a canned solution to create a Word document in my application and just couldn't find anything that just gets to the point. I would think, and I may be making too strong of an...
2
by: FFrozTT | last post by:
I am having a problem creating a DLL with an entry point. I've been trying sub Main, DllMain, and I get nothing. When I run dumpbin - exports mydll.dll I see no entry points, also the dll when...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.