Thread: A simple Menu Problem

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    A simple Menu Problem

    Hi I have to make a menu for a general case using just if else statement and do-while , while and for loops .
    Also for the choice 1 and choice 2 after printing it should show the main menu again only for choice 3 it should exit the program .
    Thanks for your help





    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int main()
    {
    	int choice=0;
    	
    	do{
    		printf("Please select one of the choice\n\n");
    		printf(" 1) Calcultae resistance value\n");
    		printf(" 2) Help\n");
    		printf(" 3) Exit\n");
    		
    		scanf("%d",&choice);
    		
    		if (choice<1 || choice>3) 
    		{
    			printf("Invalid choice\n");
    			printf("Select again\n\n");
    			choice=0;
    		}			
    		
    	}
    	while(choice<1 || choice>3);
    	
    
    	
    do {
    	
    		
    		if (choice==1) 
    		{
    			printf("The value is\n");
    			choice=0;
    		}			
    
    		
    		
    		else if (choice==2) 
    		{
    			printf("The help menu  \n");
    			choice=0;
    		}			
    		
    	
    
    	} 
    	while (choice!=3 );
    
    	system("exit"); 
    	return 0;
    		
    }

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I'd say you don't need the second loop, and consider changing the conditions of the first loop to ... } while ( choice != 3 );

    Then do the if-else tree in the first loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating menu, problem
    By Tehy in forum C Programming
    Replies: 2
    Last Post: 04-13-2007, 05:19 AM
  2. simple JPEG problem
    By the bassinvader in forum C Programming
    Replies: 6
    Last Post: 10-05-2006, 05:45 PM
  3. Probably simple problem with classes
    By slaad in forum C++ Programming
    Replies: 6
    Last Post: 12-14-2004, 12:35 AM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM