0

So I figured everything out except why when I configure the program it doesnt print anything. No hashes no spaces!

    #include <cs50.h>
    #include <stdio.h>

   int main(void)
     {
    int height, rows, spaces, hashes;

       do 
      {   
          printf("Mario's Prymid Height: ");
         height = GetInt();
       } 
         while (height <= 0 || height >= 23);

       for (rows = 0; height <= rows; rows++)
          {
           for (spaces = height - 1; spaces == 0; spaces-- )
             {
                 printf (" ");
             }
          for (hashes = rows + 2; hashes <= height; hashes++)
             {
                 printf ("# \n");
             }
      }
     return 0;
    }

1 Answer 1

2

See anything wrong here?

for (rows = 0; height <= rows; rows++)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

3
  • Umm I know the row is eqaul to height the user inputs put im having hard time translating to c. Is it the rows equal 0? Should it be for (rows = 0; height = rows; rows++)?
    – Alice
    Jul 12, 2017 at 23:05
  • Let's say that your pyramid has 5 rows. (Actually the only thing that matters here is that height will be 0 or more.) In your for loop, row is initialized at 0. Immediately, it tests whether height is less than rows. Since height is never going to be less than 0, the loop will never start. So, what's wrong with the for loop setup?
    – Cliff B
    Jul 12, 2017 at 23:17
  • Oh ok that makes since so rows wont be equal to 0.
    – Alice
    Jul 13, 2017 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .