我已经用谷歌搜索并阅读了堆栈上的帖子,但仍然不知道我的代码在这个问题集上哪里出错了……它只是不断询问输入“高度”。输入高度后,它没有进入下一步,似乎陷入了无限循环。
大脑融化。
请帮忙指出我的代码哪里出错了。非常感谢。
#include <cs50.h>
#include <stdio.h>
int main(void)
{
int height;
do
{
printf ("height: ");
height = get_int();
}
while (height >= 0 || height <= 23);
for (int loop = 0; loop <= height; loop++)
{
for (int space = height - 1 - loop; space > 0; space--)
printf(" ");
for (int hash = 2 + loop; hash < height; hash++)
printf("#");
printf("\n");
}
}
最佳答案
在这里,在 do while 循环中,您给出的条件是,无论您放置什么高度,循环都应该继续,因为每个数字要么是 >=0
。或 <=23
.
而是将条件更改为 while(height<0||height>23)
关于C - CS50 pset1 马里奥金字塔挑战,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714227/