Need Help With My Loops??

This is a discussion on Need Help With My Loops?? within the C Programming forums, part of the General Programming Boards category; Hello All, I am in a c..programming class at my college.. We were given a problem..and its been bothering me ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    Need Help With My Loops??

    Hello All,
    I am in a c..programming class at my college.. We were given a problem..and its been bothering me now for 3 days..I can't figure out how to get this program to work.. I could simply write 7 identical for loops to get the desired output, but that is cheesy, like using multiple printf statements to get the desired output..
    Here is my problem? And my code. Can someone at least give me a clue..as to what i'm doing wrong.. thanks..
    Code:
    /*Write a program that would draw a number diagram like this:
    
    7 7 7 7 7 7 7
    6 6 6 6 6 6
    5 5 5 5 5
    4 4 4 4 4
    3 3 3 3
    2 2 2
    1 1
    0
    
    0
    1 1
    2 2 2
    3 3 3 3
    4 4 4 4 4
    5 5 5 5 5 5
    6 6 6 6 6 6 6
    7 7 7 7 7 7 7 7
                                 */
    
    
    
    
    #include <stdio.h>
    int main()
    {
        /* Declaring Variables */
    int number =7;
    int i;
    int j;
    int sum=7;
        /* While Loop for 7 Lines of Output */
    while(number <= 7)
    {
    
                /*  For Loop for Printing out numbers on Line */
    for(i=0; i<j; ++i)
    printf("%d", sum);
    
                 /* After For Loop Decrease Sum by 1 */
                 /* Go Down One Line */
    sum=sum-1;
    printf("\n");
    }
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Your loop is counting down from 7, so don't stop once it's bigger than seven, continue while it's bigger than 0 (or -1 depending on how you write it).


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

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3
    Well I need 7 Lines of output.. So I figured i would need a loop that counts down from 7??
    7777777
    666666
    55555
    4444
    333
    22
    1
    0
    I'm trying to do this program in sections..I'm working on the first count down..before i even think about the bottom part..

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3
    Can anyone help me with my loop problem? I'm kind of jammed up for time.. Already late on this assignment..

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I didn't say don't make it count down. I said stop checking to see if it's less than 7. Obviously it's less (or equal to) than seven! You start at seven and count down! Why wouldn't it be less than 7? I said stop when you reach zero! Read damnit!


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loops Trouble
    By rlframpton in forum C Programming
    Replies: 2
    Last Post: 04-17-2009, 02:08 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  3. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  4. for loops in C
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-15-2001, 06:09 PM
  5. exiting loops with ease?
    By KingRuss in forum Game Programming
    Replies: 3
    Last Post: 09-24-2001, 09:46 PM

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