Thread: Employee array/loop help

  1. #1
    Unregistered
    Guest

    Employee array/loop help

    I've a got a huge program to write for an assignment and I'm needing a little help. Basically I have to write a program that contains a loop and an array. I know the basics of arrays and loops but in C I'm lost! I learnt how to write the a loop like the one below, but it doesn't do the job properly. The syntax isn't correct. All I need to know is how to perform a loop so that people enter their names one by one in an array (for four people). I know the following code has the right idea, but it's not right to syntax. I'd be most greatful if you could help.


    for (count = 0; count <=3; count = count + 1)
    {
    printf("Enter name:\n");
    scanf(name[count]);
    count = count + 1;
    }

    return(0);

    count = 0

    for (count = 1; count <=50; count = count + 1)
    {
    printf(name[count])
    count = count + 1
    }

    return(0);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. make your loops consistent - is it 3 or 50 ?
    for (count = 0; count <=3; count = count + 1)
    for (count = 1; count <=50; count = count + 1)

    2. Arrays always start at 0, so if you had
    char name[3][20];
    The correct loop would be
    for (count = 0; count <3; count = count + 1)

    3. printf and scanf usage (read the manual)
    These routines have as their first parameter a control string which tells the function what to do, so
    scanf(name[count]);
    would be
    scanf( "%s", name[count]);

    And
    printf(name[count])
    would be
    printf( "%s", name[count])

    4. What's with the return(0); ?
    I would think that having done one loop, you would want to do the other.

    5. You're incrementing count twice

    for (count = 0; count <3; count = count + 1 )
    {
    ...
    count = count + 1 ;
    }
    Delete the one between the {}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Payroll- I'm completely stuck
    By stno17 in forum C Programming
    Replies: 7
    Last Post: 11-29-2007, 03:17 AM
  2. Code Questions
    By Taikon in forum C Programming
    Replies: 8
    Last Post: 03-02-2005, 08:31 AM
  3. poiner problem in function
    By caws in forum C Programming
    Replies: 2
    Last Post: 04-22-2003, 06:01 PM
  4. linked lists problem
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 06-17-2002, 10:55 AM
  5. (structure+array+pointer)to make a simple database
    By frankie in forum C Programming
    Replies: 5
    Last Post: 04-26-2002, 05:14 PM