really easy question! help!!!

This is a discussion on really easy question! help!!! within the C Programming forums, part of the General Programming Boards category; I have a really simple assignment. My assignment is to write a program that counts from 1...1000 and displays five ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    23

    Lightbulb really easy question! help!!!

    I have a really simple assignment.
    My assignment is to write a program that counts from 1...1000 and displays five numbers across the screen prior to adding the newline character \n

    Ex:
    1,2,3,4,5
    6,7,8,9,10
    11,12,13,14,15


    the only problem i have is to print out only 5 at a time. I can print out one at a time or al at once. Help on printing ony 5 perline?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    2 loops, 1 nested in the first. Or a bit of math and 1loop.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    I have this

    Code:
    #include<stdio.h>
    int main(void)
    {
       int num;
    
       num=1;
       while (num<1000)
       {
        printf("%d",num);
        num=num+1.0;
        }
        return 0;
    }

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I'm not going to give you the answer since it's your assignment, but 1.0 is for floats/doubles (not integers).

    I'll be more specific, use 2 for loops, the 2nd runs inside the first which runs from 1 to 1000 inclusive the second counts from 0 to 5 incrementing the first loop as it does, printing each number (from the first loop). Since the 2nd loop runs per 5 numbers the first loop is responsible for printing the newline. Hint: You'll need 2 integer variables.

    BTW your program will only print [1, 1000) ie, 1- 999 -- you'd want num <= 1000

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    i think i kinda know what you are saying...
    more hints please.
    do not be afraid to help me out it is just stupid homework.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Okay, my homebrand pseudo-code is as close as you'll get
    Code:
    i is an integer
    z is an integer
    
    WHILE i <= 1000
        FOR z = 0 ; z < 5 ; INCREMENT z   /* I dunno how to do for loops in pseudo :( */
            PRINT i
            INCREMENT i
        ENDFOR
        PRINT "newline"
    ENDWHILE
    I suppose you could use 2 for loops, 2 while loops or 1 while and 1 for

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    thanks, but we have not learned how to do for loops yet. I am starting to wonder if my retarted instructor gave us a program on something we have not learned yet.

    ANYONE ELSE WNA TOT HELP A LOST GUY IN THIS!!!!!!!!!!!!!!

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    No-one is going to do your homework for you, seriously (not to mention it's against this boards' rules).

    If you've learnt while loops but not for loops you can still easily do it.

    Code:
    i is an integer
    z is an integer
    
    WHILE i <= 1000
        z = 0
        WHILE z < 5
            PRINT i
            INCREMENT i
            INCREMENT z
        ENDWHILE
        PRINT "newline"
    ENDWHILE
    Seriously, I can't give it away anymore.
    Last edited by zacs7; 10-21-2007 at 05:14 PM.

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    "head falls on keyboard"
    "thinks dirty tought about programing instructor"

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    ok well thanks for your help anyways. I will experiment around with another while loop.
    Thanks

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129

  12. #12
    Registered User
    Join Date
    Oct 2007
    Posts
    23
    more help? please?...:[

  13. #13
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    We can't, it's against the rules -- you're the one in the class not us

    If we help you any more you'd have the solution. You should be able to look at the psuedo-code in post #8 and work out that, INCREMENT i means ++i in C, just as
    Code:
    WHILE i <= 1000 ... ENDWHILE
    is
    Code:
    while(i <= 1000) {  ...  }
    in C.

  14. #14
    Registered User
    Join Date
    Oct 2007
    Posts
    23

    Angry

    Ok first of all i have to most craziest professor in the world he sucks!!! HE does not do s***. He comes to class and ask us if we have questions and tells us to read a booksa dn gives us homework assignments like this one here that has stuff the book does not talk about.
    So lets see!



    Code:
    #include<stdio.h>
    int main(void)
    {
       int num; /*defines stupid num thjing*/
       int ???????   /*I NEED TO DEFINE SOMETHING HAVE NO IDEA WHAT*/
       num=1; /*makes it one the starting place*/
       while (num<1000) /*from 1-1000 thats where i want to go...*/
        while(WHAT THE HECK GOES IN HERE) /*i need something that will make it print out only 5 per line! BUT NOOO THIS STUOID BOOK WONT TELL ME S###*/
    
     {
        printf("%d",num);  /*PRINTS OUT THE S****/
        num=num+1.0;     /*INCREMENTS THE THINGY*/
        }
        return 0;    /*Return*/
    }

  15. #15
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Being agressive won't give you answers. And maybe you should read what people are writing, there's good advice out there in this topic...

    Let's say you have to print numbers from 1 to 1000. And let's says you have to print something like

    1,2,3,4,5,'\n',6...

    So, everytime the current number is a multiple of 5, you have to print a '\n' after that character, else you print a comma. This translate to:

    Code:
    printf("%d", currentNumber);
    if (currentNumber % 5 == 0)
    {
        putchar('\n');
    }
    
    else
    {
        putchar(',');
    }
    Anyway.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. easy Vector contructor question
    By noodle24 in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2006, 08:43 PM
  2. Another Embarassingly Easy Question
    By almo89 in forum C Programming
    Replies: 2
    Last Post: 02-11-2006, 04:59 PM
  3. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 01:36 AM
  4. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 11:43 PM
  5. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 01:19 PM

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