0

I have been trying to make my pyramid from left aligned to right aligned but i am confused on how to do it. This is the code i am using. Edit: i have changed the code but i have been getting an error

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

int main(void)
 {
    int height;
    do
{
    //asks user for number between 1 and 8
        height = get_int("please give height: ");
}
    while (height < 1 || height > 8);
    //prints rows (i)
    for (int rows = 0; rows < height; rows++)
    {
            //prints spaces (j)
        for (int spaces = 0; spaces < height - rows; spaces++)
       {
            printf(".");
       } 
             printf("\n"); 
          }

          for (int hashes = 0; rows < height - rows; hashes++)
            {
                printf("#");
            }
                printf("\n");

 } 



user gets prompted and writes number between 1 and 8
user types 4

Expected
...#
..##
.###
####
    Actual output
....
...
..
.


mario.c:24:48: error: use of undeclared identifier 'rows'
          for (int hashes = 0; rows < height - rows; hashes++)
                                               ^
mario.c:24:32: error: use of undeclared identifier 'rows'
          for (int hashes = 0; rows < height - rows; hashes++)
                               ^
2 errors generated.
<builtin>: recipe for target 'mario' failed
make: *** [mario] Error 1

i am trying to print hashes and use the rows interger but for some reason the error says it is am undefined interger.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

I think the error is because you're curly brackets {} in your first and second for loops are mixed up. It looks like you're trying to do three loops that are nested inside each other; however, your third loops is outside the first one because you have an extra } in the middle of your code for the second loop. The variable row is declared in the first loop and the third loop doesn't know what that means since it is outside the first loop.

Sticking to the class's recommendations about indentation helped me keep this straight.

rfii
  • 562
  • 3
  • 14