为什么我会收到def __init__()
和"expected ';' after expression
的错误?这是我的代码:
expressions result unused
答案 0 :(得分:4)
您收到此错误是因为您无法使用else
进行条件检查。您可能想要使用else if
但是,您会注意到的一点是,这两种情况都是全局性的,因此您不需要对条件进行else if
检查。只有else
没有任何条件检查就可以为你完成工作。
另外,根据你给出的条件检查,它永远不会是真的。由于height
不能同时大于23
且低于1
。您需要的是||
支票,而不是和&&
所以,你的代码将成为
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("How tall do you want your pyramid to be?\n");
int height = GetInt();
if (height > 23 || height < 1)
{
printf("Please use a positive number no greater than 23:\n");
}
else
{
printf("Thanks!\n");
}
}
答案 1 :(得分:2)
没有
之类的东西else (height > 0 && height <= 23)
否则意味着其他一切,所以你不能给别人一个条件。 如果是^^
,请使用else