Getting the user to set the loop

This is a discussion on Getting the user to set the loop within the C Programming forums, part of the General Programming Boards category; I'm familiar which how to do various loops like do...while and case blocks but my question is: How do I ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    68

    Getting the user to set the loop

    I'm familiar which how to do various loops like do...while and case blocks but my question is:
    How do I set the counter by the number the user input?
    Basically, the user enters a number and it increments by that amount.
    For example if I enter 5 the display shouldread 5, 10 , 15, 20...etc
    Any help that can be offered would be really appreciated.
    Thanks,
    Extro

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    FAQ > How do I... (Level 1) > How do I get a number from the user (C)
    Code:
    for ( i = 5; i < 20; i += number )
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    68
    oops, in the FAQ, I didnt think of checking it
    -sorry about that.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Or to further it a bit:
    Code:
    for( counter = startvalue; counter < endvalue; counter += incrementation )
    Now, we could have some real fun:
    Code:
        for( counter = startvalue;
             test == lessthan ? counter < endvalue :
             test == greaterthan ? counter > endvalue : 0;
             counter += iterator )
        {
            printf("counter is %d\n", counter );
        }

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is my loop badly set up?
    By mabufo in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2006, 03:40 PM
  2. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 03:48 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  5. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 12:52 PM

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