need a lil help with some loops

This is a discussion on need a lil help with some loops within the C Programming forums, part of the General Programming Boards category; ok here;s my code: Code: #include <stdio.h> main() { int shape1, shape2, shape3, shape4, shape5; int base1, base2, base3, base4, ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    40

    need a lil help with some loops

    ok here;s my code:

    Code:
    #include <stdio.h>
    
    main()
    {
      int shape1, shape2, shape3, shape4, shape5;
      int base1, base2, base3, base4, base5;
      int height1, height2, height3, height4, height5;
      int rot1, rot2, rot3, rot4, rot5;
      int row, col;
      int space, t, s;
    
      printf("Shapes\n\n");
      scanf("%d%d%d%d", &shape1, &base1, &height1, &rot1); 
    /* ok heres the inputs for the base and height */
    
    
    
      if(shape1 == 1 || shape1 == 2)
        {
          if(shape1 == 1)
            {
              /* pyramid */
                  for (row = 1; row <= height1; row++)
                    {
                      for (space = height1; space >= row; space--)
                        printf(" ");
                      for (col = 1; col <= (row * 2 - 1); col++)
                        printf("*");
                      printf("\n");
                    }
            }
          else
            {
              /* top */
                  for (row = 1; row <= height1; row++)
                    {
                      for (space = height1; space >= row; space--)
                        printf(" ");
                      for (col = 1; col <= (row * 2 - 1); col++)
                        printf("*");
                      printf("\n");
                    }
              /* bottom of diamond */
                  for (row = 1; row <= height1 - 1; row++)
                    {
                      for (space = 1; space <= row + 1; space++)
                        printf(" ");
                      for (col = 1; col <= height1 * 2 - (row * 2 + 1); col++)
                        printf("*");
                      printf("\n");
                    }
            }
    
        }
    
      return 0;
    }
    and the output for input: 1 5 6 0 is:

    Code:
          *
         ***
        *****
       *******
      *********
     ***********
    which isn't right, i can't figure out what i need to change to make ti work, can anyone help me out some?
    Last edited by blindleaf; 03-16-2003 at 02:17 PM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Eh? What's the problem? That looks like a nice pyramid to me.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Platypussy
    Guest
    It is right because it follow the logic of your program.
    Though what you mean is, I want it to do X, not Y. Could you edit your post and add some comments? Because otherwise, no one will have a clue what you would like it to actually do.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    40
    ok the problem that exists is that i dont know how to make it work with the given height and base values, i need to have the base and height values incorportated into the for loops, anyone understand what i mean? i have put the part where the values are inputted in red. Please any help would be nice. thanks

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Could you please explain what will be the correct output for 1 5 6 0 cuz I can't understand what you're t'lking 'bout.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    40
    Originally posted by Vber
    Could you please explain what will be the correct output for 1 5 6 0 cuz I can't understand what you're t'lking 'bout.
    ok the correct output for 1 5 6 0 would be a triangle with the base of 5 and height of 6. I know that this isn't possible but i want the second number to be the base input and the 6 for the height i'll figure out the error checking later, i basically want to be able to make the triangle with the given dimensions though. All triangles are isosceles.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    40
    can anyone help?

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please don't bump your posts.

    In answer to your question...

    Your code already reads numbers from the user and uses them in the loops to create the triangles. So what is the problem again? Is it that the dimensions aren't correct? If so, simply trace your program through, working out how each number is used, and what you need to do to it to make it work for you.

    >> I know that this isn't possible
    If it's not possible, then define yourself some criteria that is possible, or you'll only get more confused.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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, 01:08 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. Evaluation of nested loops
    By Mister C in forum C Programming
    Replies: 2
    Last Post: 08-13-2004, 01:47 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  5. exiting loops with ease?
    By KingRuss in forum Game Programming
    Replies: 3
    Last Post: 09-24-2001, 08:46 PM

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