Answer the question
In order to leave comments, you need to log in
How to equate two variables in a loop in C just like in JS?
int main (void)
{
int row= 0;
int height;
do
{
printf("Height:");
height = GetInt();
} while ( 0 > height || height > 23 );
for ( int i=height; i>=row;i-- ) {
for ( int j=0; j<=i ; j++ ) {
printf(" ");
}
for ( int k= j ; k<=row+height; k++ ) {
printf("#");
}
printf("\n");
}
}
file.c:21:23: error: use of undeclared identifier 'j'
for ( int k= j ; k<=row+height; k++ ) {
^
Answer the question
In order to leave comments, you need to log in
declare j before for
"A variable can also be declared in the initializing part of a for statement. In this case, the scope of the variable (or variables) extends to the end of the statement." - that is, j is only visible in the for loop in which it was initialized
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question