terminate loop

This is a discussion on terminate loop within the C Programming forums, part of the General Programming Boards category; Having problem in terminating my loop. Any help would be good int main(void) { int num=0, signal=0; while(signal<100) { scanf("%d", ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    14

    Question terminate loop

    Having problem in terminating my loop. Any help would be good

    int main(void)
    {
    int num=0, signal=0;

    while(signal<100)
    {
    scanf("%d", &signal);
    {
    if (signal>7)
    {
    printf("During minutes %d, traffic flow is %d vehicles per minute\n", num, signal);
    }
    num++;
    }
    }
    return (0);
    }

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    your parentheses were a bit muddled up thats all
    Code:
    int main(void)
    {
        int num=0, signal=0;
    
        while(signal<100)
        {
            scanf("%d", &signal);
        }    
        if (signal>7)
        {
            printf("During minutes %d, traffic flow is %d vehicles per minute\n", num, signal);
        }
        num++;
    
    
        return (0);
    }
    (even though the program doesnt actually do anything)

    [edit] did you mean this?
    Code:
    while(signal<100)
    to terminate this loop you have toenter a number greater than 100, but again i dont see what this program is supposed to do
    Last edited by sand_man; 09-06-2004 at 09:31 PM.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I really don't think he wants that
    Code:
    int main(void){
         int num=0, signal=0;
         while(num<100){
              scanf("%d", &signal);
              if (signal>7){
                   printf("During minutes %d, traffic flow is %d vehicles per minute\n", num,  signal);
              }
              num++;
          }
         return (0);
    }
    maybe this but the sentence doesn't make sense to me. I think you want to compare num in the while loop not signal

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    14
    Well this program is for my pipe redirection in unix... anyway.. thanx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-01-2008, 09:09 AM
  2. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 02:48 AM
  3. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  4. how to terminate for loop
    By Chobo_C++ in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2004, 05:43 PM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM

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