Thread: Simple Loop

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    Simple Loop

    Im trying to write a C program to prompt the user to enter 9 integers and then display them in 3 lines all seperated by commas.
    example:
    1, 2, 3,4,5, 6, 7, 8, 9

    1,2,3
    4,5,6
    7,8,9

    This is what i have so far

    #include <stdio.h>

    void main()
    {

    printf("Please enter your first number: ");

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    First of all, never use void main, it is always int main (read the FAQ for answer why). Second: The topics you will want to read more about would be: loops, arrays and getting input from user. I suggest going over the tutorials here (C programming.com - Your Resource for C and C++ Programming) for details about those topics.

    For a start in how a basic loop is constructed here is some pseudo-ish code:

    Code:
    while(someConditionIsFulfilled)
    {
        // Do something
    }
    This will loop while someConditionIsFulfilled is true (ie, not equals 0).
    Last edited by Shakti; 05-28-2010 at 08:07 AM.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    Im trying to write a C program to prompt the user to enter 9 integers and then display them in 3 lines all seperated by commas.
    example:
    1, 2, 3,4,5, 6, 7, 8, 9

    1,2,3
    4,5,6
    7,8,9

    This is what i have so far

    #include <stdio.h>

    int main()
    {

    printf("Please enter your first number: ");

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I think we're already in a loop here.
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Looks that way. Nobody is going to do your homework for you. You will have to show some more effort and a willingness to learn. Go do what i told you in my first post and come back when you run into more specific problems.

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    This will loop until someConditionIsFulfilled is true (ie, not equals 0).
    You mean the opposite - it will loop until the condition is false.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    damnit! yes it should say it will loop while someConditionblablabla is true (ie not 0)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. having problem with a simple loop
    By everyone0 in forum C Programming
    Replies: 6
    Last Post: 05-28-2010, 05:22 AM
  2. Trying to figure out a simple loop....
    By chadsxe in forum C++ Programming
    Replies: 9
    Last Post: 01-05-2006, 01:31 PM
  3. simple collision detection problems
    By Mr_Jack in forum Game Programming
    Replies: 0
    Last Post: 03-31-2004, 04:59 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:13 AM