[英]Getting an undeclared identifier error for "i"
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height;
do
{
// Asking for # of blocks
height = get_int("Height: ");
}
// Setting min/max height
while (height < 1 || height > 8);
// For columns
for (int i = 0; i < height; i++)
// For spaces
for (int j = height - 1; j > i; j--)
{
printf(" ");
}
// For the #'s
for (int j = 0; j <= i; j++)
{
printf("#");
}
printf("\n");
}
C 不是 Python。
这段代码
// For columns
for (int i = 0; i < height; i++)
// For spaces
for (int j = height - 1; j > i; j--)
{
printf(" ");
}
// For the #'s
for (int j = 0; j <= i; j++)
{
printf("#");
}
相当于
// For columns
for (int i = 0; i < height; i++)
{
// For spaces
for (int j = height - 1; j > i; j--)
{
printf(" ");
}
}
// For the #'s
for (int j = 0; j <= i; j++)
{
printf("#");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.