我正在上一门入门课程(CS50),但我在编写代码时遇到了问题。
#include <cs50.h>
#include <stdio.h>
int main (void)
{
int height;
do
{
printf("Make your own pyramid!\nDetermine its height by entering an integer from 0 to 23.");
height = GetInt();
}
while (height < 0 && height > 23);
int row;
int column;
for (int row = 0; row < height; row++)
{
if (int row == 0)
{
for (int column = (height - 2); column > 0;)
{
printf(" ");
}
{
printf("##");
}
}
else
{
//etc
出现的错误是:
mario.c:18:13: error: expected expression
if (int row == 0)
^
1 error generated.
make: *** [mario] Error 1
我已经尝试查找“预期表达”的含义,但所有定义都超出了我的理解范围。我该如何解决这个问题?
答案 0 :(得分:1)
我修复了问题区域。声明整数后,您无法在同一函数中重新声明它。此外,for循环需要三个参数,而不是两个。
int height=100; // change 100 to desired height higher than 2.
int row; // declared here (don't use int row again in function)
int column;
for (row = 0; row < height; row++)
{
if (row == 0)
{
for (column = (height - 2); column > 0;column--)
{
printf(" ");
}
}
printf("##");
}