C - CS50 pset1 马里奥金字塔挑战

标签 c cs50

我已经用谷歌搜索并阅读了堆栈上的帖子,但仍然不知道我的代码在这个问题集上哪里出错了……它只是不断询问输入“高度”。输入高度后,它没有进入下一步,似乎陷入了无限循环。

大脑融化。

请帮忙指出我的代码哪里出错了。非常感谢。

 #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/

相关文章:

C 编程 : Using function to return size of array

c - Node : Performance of Native Addon vs External Binary

c - sendto() "invalid argument"错误,Linux 上的 IPv6 原始 udp 套接字

c - 重新提示用户,直到他/她输入大于 1 的正整数值

c - 区分 trie 中的单词

c - 在 C 中,我有一个浮点变量减少了不正确的数量

python - OpenMP、Python、C 扩展、内存访问和邪恶的 GIL

c - 在 Mac 上释放未对齐的指针

CS50 pset3 径流

c - 无限 do-while 循环,应该寻找 JPEG header