Skip to content

Instantly share code, notes, and snippets.

@El-Wumbus
Created January 27, 2022 14:02
Show Gist options
  • Save El-Wumbus/046e6641c019562e51723d6b162a356d to your computer and use it in GitHub Desktop.
Save El-Wumbus/046e6641c019562e51723d6b162a356d to your computer and use it in GitHub Desktop.
A menu
#include <stdio.h>
int menu()
{
printf("Select a menu option\n Option one (1)\n Option two (2)\n Option 3 (3)\n");
int menuSelection;
printf("Selection: ");
scanf("%d", &menuSelection);
switch(menuSelection)
{
case 1:
printf("Option One\n");
return 0;
break;
case 2:
printf("Option Two\n");
return 0;
break;
case 3:
printf("Option Three\n");
return 0;
break;
default:
printf("Err: improper input\n");
return 1;
break;
}
}
int main()
{
int failure = menu();
if ( failure >= 1 )
{
printf("would you like to try again? [y/N] ");
char reRun;
scanf("%s", &reRun);
if ( reRun == 'y' || reRun == 'Y' )
{
printf("\n");
menu();
} else
{
return 0;
}
}
else
{
return 0
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment