me again, sorry bout last post

This is a discussion on me again, sorry bout last post within the C Programming forums, part of the General Programming Boards category; okay, this is what i have and am attempting to use to make a user option quit loop, once it ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    Unhappy me again, sorry bout last post

    okay, this is what i have and am attempting to use to make a user option quit loop, once it hits the first print statement in the loop it just keeps repeating it. how can i fix this? and is this code even remotely close to what it should look like

    { int id_num[20];
    int num_chair[20];
    int num_sofa[20];



    {int x=1;

    printf("Enter <0> under ID number when finished\n");
    scanf("%d", &id_num[x]);

    while(id_num[x] != 0)
    printf("Enter the amount of chairs you desire to order\n");
    scanf ("%d", &num_chair);
    printf("Enter the amount of sofas you desire to order\n");
    scanf ("%d", &num_sofa);
    printf ("Enter <0> under ID number when finished");
    scanf("%d", &id_num);
    x++;
    }
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    75

    Hello nova



    Hello Nova


    Sorry I couldnt fix the problem didnt even read it actually just logged on and it said "welcome to our newest member Nova"
    ok man sorry about that



    later

  3. #3
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    I've found 2 errors:
    -you should use { and } after your while() if you want more then one statement to be repeated
    -when you use an array always let the compiler know where you want to put your stuff in.
    here's the code:

    { int id_num[20];
    int num_chair[20];
    int num_sofa[20];

    {int x=1;

    printf("Enter <0> under ID number when finished\n");
    scanf("%d", &id_num[x]);
    x++;
    while(id_num[x-1] != 0)
    {
    printf("Enter the amount of chairs you desire to order\n");
    scanf ("%d", &num_chair[x]);
    printf("Enter the amount of sofas you desire to order\n");
    scanf ("%d", &num_sofa[x]);
    printf ("Enter <0> under ID number when finished");
    scanf("%d", &id_num[x]);
    x++;
    }
    }
    }


    I hope this works as you want it
    bye

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Code:
    { 
    int id_num[20]; 
    int num_chair[20]; 
    int num_sofa[20]; 
    
    
    
    {
    int x=0; 
    
    printf("Enter <0> under ID number when finished\n");
    scanf("%d", &id_num[x]); 
                
    while(id_num[x] != 0) {
               printf("Enter the amount of chairs you desire to order\n"); 
               scanf ("%d", &num_chair[x]);/*you missed array elements*/ 
               printf("Enter the amount of sofas you desire to order\n"); 
               scanf ("%d", &num_sofa[x]); 
               x++; 
               printf ("Enter <0> under ID number when finished");
               scanf("%d", &id_num[x]);  
          } 
    }
    Last edited by bigtamscot; 10-15-2001 at 08:13 AM.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help (Trying to post message)
    By mrkm in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-06-2003, 04:05 PM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM
  4. post update
    By iain in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-12-2001, 10:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21