Current location - Recipe Complete Network - Complete cookbook - How to write a menu in C language?
How to write a menu in C language?
# contains "stdio.h"

# contains "stdlib.h"

# contains "dos.h"

# contains "windows.h"

char choice 1;

void main()

{

void menue 1();

Printf ("Welcome to Ben's homework query system!" " );

menue 1();

}

Void menu 1 ()

{

void choice menu 1();

Printf ("\ nPlease select the chapter you want to view according to the following list:");

Printf ("\ n no \ tChapter I \ n1\ tChapter I \ n2 \ Chapter II \ n");

Printf ("Please enter a numerical choice:");

choice menu 1();

}

void choice menu 1()

{

choice 1 = getch();

Switch (select 1)

{

void menu chapter 1();

void menu chapter 2();

void menue 1();

case ' 1 ':menu chapter 1(); Break;

case“2”:menue chapter 2(); Break;

Default value: printf ("\ nInput error! Please re-select! \n”),menue 1();

}}

void menu chapter 1()

{

char choiceex

Printf ("\ nyou selected chapter %c", choice1);

Printf ("\ nPlease choose the title of this chapter now." );

Printf ("\ nPlease select a theme according to the following list:");

Printf ("\ nNo .. \ tthe title is no. \ n1\ t1\ N2 \ tQuestion 2 \ n ");

Printf ("Please select:");

Switch (choiceex=getch ())

{

void c 1 _ 1();

void c 1 _ 2();

case ' 1 ':c 1 _ 1(); Break;

Case "2": c1_ 2 (); Break;

Default value:

Printf ("\ nYou idiot! This may also be wrong! I won't let you get re-elected! ”);

Printf ("\ nPress any key to exit!" );

getch();

Exit (0);

}

}

Void menu Chapter 2 ()

{

char choiceex

Printf ("\ nyou selected chapter %c", choice1);

Printf ("\ nPlease choose the title of this chapter now." );

Printf ("\ nPlease select a theme according to the following list:");

Printf ("\ nNo .. \ tthe title is no. \ n1\ t1\ N2 \ tQuestion 2 \ n ");

Printf ("\ nPlease select:");

Switch (choiceex=getch ())

{

void C2 _ 1();

void C2 _ 2();

case ' 1 ':C2 _ 1(); Break;

Case "2": C2 _ 2 (); Break;

Default value:

Printf ("\ nYou idiot! This may also be wrong! I won't let you get re-elected! ”);

Printf ("\ nPress any key to exit!" );

getch();

Exit (0);

}

}

void c 1_ 1()

{

char howtorun

Printf ("Please select the inspection method now:");

Printf ("\ nNo \ tCheck method \ n1\ tRun the program \ n2 \ View the source code \ n3 \ Return to the main menu \ n4 \ Exit the program \ n");

Printf ("Please select:");

switch(howtorun=getch())

{

void runc 1 _ 1();

void menue 1();

case ' 1 ':runc 1 _ 1(); Break;

Case '2':printf("\n "), system(" type \ \ Cai Dan \ \ Chapter1\ c1_/kloc"), printf("\n), getch (. Break;

Case "3": menue1(); Break;

Case "4": exit (0); Break;

Default value:

Printf ("The program is coming to an end! Ha ha ha ... ");

Printf ("Press any key to end the program!" );

getch();

Exit (0);

}}

void c 1_2()

{

Printf("c 1_2 is ok! " );

}void c2_ 1()

{

Printf("c2_ 1 is OK! " );

}void c2_2()

{

Printf("c2_2 is OK! " );

}

void runc 1_ 1()

{

int a,b,max

Printf ("\ nPlease enter two integers:");

printf("a=? ,b=? \ n ");

Scanf("%d, %d ",& i, & amp);

max = a & gtb? A: b;

Printf ("Maximum quantity is %d", max);

}

That's probably what I did. .