i want to make a menu and i am almost finished typing it. but i don't know how to return to the main menu again after an option is chosen.
my program:
Code:
#include <stdio.h>
void main_menu( );
int main( )
{
main_menu();
return 0;
}
void main_menu()
{ int selection;
printf( "*** ***** ***** ***** ***** ***** ***** ***\n" );
printf( "** * *** * *** * *** * *** * *** * *** * **\n" );
printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );
printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
printf( "**** Welcome to MY PROGRM! ****\n" );
printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );
printf( "** * *** * *** * *** * *** * *** * *** * **\n" );
printf( "*** ***** ***** ***** ***** ***** ***** ***\n\n" );
printf(" What is you name?");
scanf("%s");
printf("\nPlease choose one of the options below and enter its number: \n\n");
printf(" 1) Count the total number of words\n");
printf(" 2) Count the total number of vowels\n");
printf(" 3) Count the total number of capital letters\n");
printf(" 4) Reverse the text inputted\n");
printf(" 5) Capitalize the first letters and lowercase other letters\n");
printf(" 6) Exit\n\n");
printf("Choose an option: ");
scanf("%d", &selection);
switch(selection){
case 1:
{
/*function 1*/
}
break;
case 2:
{
/*function 2*/
}
break;
case 3:
{
/*function 3*/
}
break;
case 4:
{
/*function 4*/
}
break;
case 5:
{
/*function 5*/
}
break;
case 6:
{
int ch;
fflush(stdin);
do
{
puts("\nAre you sure you want to quit ? (Y/N)\n");
ch = getc(stdin);
if (ch == 'y')
{
printf("\nThank you for using ! Byebye!\n");
exit(0);
}
else if (ch == 'n')
{
puts("\nReturning to main menu...\n\n");
main_menu();
return ;
}
}while(ch != 'n' || ch != 'y');
break;
}
break;
default:
printf("\nInvalid selection! Program will end automatically.\n");
break;
}
}
i want to know how i can return to the main menu again without showing the following text
Code:
printf( "*** ***** ***** ***** ***** ***** ***** ***\n" );
printf( "** * *** * *** * *** * *** * *** * *** * **\n" );
printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );
printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
printf( "**** Welcome to MY PROGRM! ****\n" );
printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );
printf( "** * *** * *** * *** * *** * *** * *** * **\n" );
printf( "*** ***** ***** ***** ***** ***** ***** ***\n\n" );
printf(" What is you name?");
but directly show the following part to the user.
Code:
printf("\nPlease choose one of the options below and enter its number: \n\n");
printf(" 1) Count the total number of words\n");
printf(" 2) Count the total number of vowels\n");
printf(" 3) Count the total number of capital letters\n");
printf(" 4) Reverse the text inputted\n");
printf(" 5) Capitalize the first letters and lowercase other letters\n");
printf(" 6) Exit\n\n");
printf("Choose an option: ");
Someone please help! i tried so many times but i still fail! =(
please give me some examples!