Thread: Menu driven program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    INDIA
    Posts
    13

    Question Menu driven program

    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("&#37;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??
    Last edited by paushali; 11-26-2007 at 10:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. menu driven interface
    By weegi in forum C Programming
    Replies: 4
    Last Post: 04-17-2004, 04:08 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. c++ program with a button menu
    By quakegod in forum C++ Programming
    Replies: 0
    Last Post: 01-07-2002, 01:09 AM