I am trying out a menu driven program which has following options:
1.Factorial of a number
2.Prime or not
3.Odd or even
4.Exit
Once a menu item is selected the appropriate action should be taken and once the action is finished ,the menu should reappear.Unless the user selects the exit option the program should continue to work.
I have typed the following program but the menu item does not reappear again.
Code:
#include<stdio.h>
#include<stdlib.h>
void main(exitmenu)
{
int opt,p,j,x=1,num,i=2,eo;
choice:
while(x<4)
{
printf("\n1.Factorial of a number");
printf("\n2.Prime number or not");
printf("\n3.Odd or Even");
printf("\n4.Exit");
printf("\nEnter your choice");
scanf("%d",&opt);
switch(opt)
case 1:
{
p=1,j=1;
while(j<=7)
{
p=p*j++;
printf("\nFactorial of %d=%d",x++,p);
}
break;
case 2:
{
printf("\nInput a number");
scanf("%d",&num);
while(i<num && num%i!=0)
i++;
if(num==i)
printf("Prime number");
else
printf("Not a prime number");
break;
}
case 3:
{
printf("\nInput a number");
scanf("%d",&eo);
if(eo%2==0)
printf("\nNumber is even");
else
printf("\nNumber is odd");
break;
}
case 4:
exit(exitmenu);
goto choice;
}
}
}
What will be the right one??