gpt4 book ai didi

c - 新手在编译c代码时出现预期的表达式错误

转载 作者:行者123 更新时间:2023-11-30 19:17:05 25 4
gpt4 key购买 nike

我正在参加入门类(class) (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

我尝试查找“预期表达”的含义,但所有定义都超出了我的理解范围。我该如何解决这个问题?

最佳答案

我修复了问题区域。一旦声明了一个整数,就不能在同一个函数中重新声明它。此外,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("##");
}

关于c - 新手在编译c代码时出现预期的表达式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com