Thread: Trying to create a menu in C that asks for user name only once

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

    Question Trying to create a menu in C that asks for user name only once

    Sorry for the long title...
    trying to figure out how to create a user menu for a pedometer program that tracks a single user for 7 days.
    I am a complete noob.
    I need my menu to ask for the user name to get started and then obviously not ask for it again.. then it needs to have them enter their weight. here is what i have so far:

    Code:
    #include <stdio.h>
    
    
    void userMenu (void);
    int getSelection(void);
    
    
    int main (void)
    
    {
    	int menuOption;
    
     userMenu();
    	menuOption = getSelection();
    
    	if (menuOption == 1)
    	{
              printf("enter name\na,weight\n");
           }
    		
    
    	return(0);
    }
    
    void userMenu (void)
    
    {
    	printf (" 1 - Create user\n");
      printf (" 2-  Edit user\n");
      printf (" 3 - Start recording\n");
      printf (" 4 - Reports\n");
      printf (" 5 - Quit \n");
    
    
    }
    
    int getSelection(void)
    {
    
    	int option;
    
    	do {
    		printf("Please choose 2 - 5");
    		scanf("%d", &option);
    	} while (option > 5 || option <1);
    
    	return (option;
    	}
    /* thanks for the help!

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Where are you getting the problem? Any error or anything else?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    So just save the name
    Code:
    char name [MAX];
    if (menuOption == 1)
    {
        printf("enter name\na,weight\n");
        scanf("%s", name);
    }
    Where to save the name depends. If this is on a PC then save it in the Hard Disk, in a file. If there is some other memory, that doesn't get erased when power is off, then save it there.
    If the power is always on, you don't need anything else. It is saved like above. You will just need to allocate memory dynamically for each user (with malloc(), calloc() ).

    NOTE: There are better options than scanf(), just giving the idea here.
    NOTE: Some memories, like RAM in a PC get erased after power is off. So you need to save informatio on Hard Disk. All variables in a program are on RAM memory (main memory)

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Talking

    So just save the name
    Code:
    Code:
    char name [MAX];
    if (menuOption == 1)
    {
        printf("enter name\na,weight\n");
        scanf("%s", name);
    }
    Where to save the name depends. If this is on a PC then save it in the Hard Disk, in a file. If there is some other memory, that doesn't get erased when power is off, then save it there.
    If the power is always on, you don't need anything else. It is saved like above. You will just need to allocate memory dynamically for each user (with malloc(), calloc() ).

    NOTE: There are better options than scanf(), just giving the idea here.
    NOTE: Some memories, like RAM in a PC get erased after power is off. So you need to save informatio on Hard Disk. All variables in a program are on RAM memory (main memory)
    I can just save it to a flash drive right?...thanks for that info.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create menu with do while loop advice pls
    By ali_1 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2006, 09:34 PM
  2. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  3. Delet Frequency in linked list
    By swishiat.com in forum C Programming
    Replies: 16
    Last Post: 12-13-2003, 02:05 AM
  4. SDI Menu App - MSVC 6
    By Unregistered in forum Windows Programming
    Replies: 7
    Last Post: 10-16-2001, 09:59 PM
  5. SDI Menu problem - Windows MSVC 6.0
    By Brown Drake in forum C++ Programming
    Replies: 0
    Last Post: 10-13-2001, 06:04 AM