0

My code looks fine but "make mario" insists that "Error: use of undeclared identifier 'j'".

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

int main(void)

{
int n;
do
 {
    n = get_int ("Height: ");
 }
while (n < 1 || n > 8);
for (int i = 0; i < n; i++)
 {

     for (int k = (8 - j); k < n; k++)
        {
            printf (".");
        }
    for (int j = (n - i); j < n; j++ )
    {

        printf("#");
    }
    printf("\n");
 }
}
1

You did use an undeclared identifier j in the second for loop. It isn't created until and only inside the following 3rd for loop.

The compiler never lies. It might mislead on occasion, but it never lies.

6
  • How do I fix it? – DCcat MarvelCatNoMore May 25 '20 at 3:09
  • figure it out yet? – Cliff B May 25 '20 at 3:20
  • I tried to move the section upwards, but nothing happened, unfortunately. – DCcat MarvelCatNoMore May 25 '20 at 3:22
  • It wouldn't help. When you define a var in the setup of a for loop, it can only be used inside the for loop. But, you don't need j in the other loop to print the spaces. Think about how to do it without j. – Cliff B May 25 '20 at 3:35
  • How do I do so? – DCcat MarvelCatNoMore May 25 '20 at 6:38

You must log in to answer this question.

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