Thread: How to make a simple menu

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    How to make a simple menu

    I want to make a menu whicch allows the user to select either male or female. if none of those two are selected, the program should print "invalid option". If the user chooses among the two... the program continues. Please help me.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    First try this if it doesn't make obvious sense to you:
    Code:
    	string x;
    	cin >> x;
    	cout << x << endl;
    That done, consider this:
    Code:
    	if (x[0] == 'X') cout << "correct";
    Usually it is easier if you write the code you have tried (or as much as you can, even if it doesn't work) and we comment.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    Code:
       
          printf("\n Select the sex (gender) of Subscriber: \n");
          printf("\n1. Male");
          printf("\n2. Female");
          scanf("%s",&s1);
    
     	char s;
    
      	FILE *sfPtr;
     	customer sex = {"",""}; 	/* Here is the error... what to put there? */
     	char choice;
    
     	if ((sfPtr = fopen("Subscriber.txt", "w")) == NULL)
     		printf("File could not be opened.\n");
     	else
     	{
     		for(s=1;s<=1;s++)
       		fwrite (&sex, sizeof(customer), 1, sfPtr);
    
     	}
     	
     	fclose (sfPtr);
     	
        printf("\nPlease enter m or f, To exit enter n: ");
        scanf("%s", &choice);
            
        while (choice != 'n')
            {
     	
     	     if ((sfPtr = fopen ("Parent.txt", "rb+"))== NULL) {
       	        printf("Unable to open file!!\n");
             }
             else {
            
                  switch (choice)
          	      {
                   case 'M':
     	           case 'm':
             		    Registration (sfPtr);
             		    fclose (sfPtr);
                        break;
                   case 'F':
                   case 'f':
                	    Find (sfPtr);
                	    fclose (sfPtr);
      	                break;
                   default:
                           printf("\nIncorrect choice, Please select a valid option: ");
      	                   break;
                   }
                }
                printf("\nPlease enter m or f, To exit enter n: ");
                scanf("%s", &choice);
            }
          
     	//Subscriber (sfPtr);
     	//Find (sfPtr);
     	fclose (sfPtr);

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why would you put anything there? And is customer a valid type name? (It doesn't appear to be.)

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    i don't know. :-/ I don't understand the above code. and I just need a very simple way to write a menu. that actually works.
    Last edited by Sharie; 04-19-2010 at 10:01 AM.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Presumably you already have an instance of the customer struct running around? You've already gotten name, and address, and ID, etc, right? So just add the response to the .sex field of that struct and you're done. You don't make a brand new customer just for this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Make simple programs start over.
    By Cooker2007 in forum C++ Programming
    Replies: 7
    Last Post: 01-16-2007, 04:08 PM
  2. Trying to make a menu screen
    By circle in forum C Programming
    Replies: 0
    Last Post: 12-07-2004, 06:06 AM
  3. (structure+array+pointer)to make a simple database
    By frankie in forum C Programming
    Replies: 5
    Last Post: 04-26-2002, 05:14 PM
  4. How to make a simple shell?
    By ranger in forum Linux Programming
    Replies: 0
    Last Post: 03-31-2002, 03:09 AM
  5. Replies: 6
    Last Post: 09-12-2001, 10:35 PM