コードは正しくコンパイルされますが、実行するたびに正しくプログラムが実行されません。Cプログラムは正しい番号を要求し続ける
#を23より小さく設定しても、もう一度試してください。 2回目に同じ番号を入力すると機能します。
23より大きい数値を入力した場合は、もう一度試してください。
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int height;
printf("What is the height of the pyramid?\n");
height = get_int();
do {
printf("The pyramid cannot be higher than 23 feet!\n");
printf("Try again!\n");
printf("What is the height of the pyramid?\n");
height = get_int(); }
while (height > 23);
if (height <= 23) {
printf("The height of the pyramid is %d feet high!\n", height);
}
}
あなたは 'do..while()'ループを使用しています...ループ条件をチェックする前に本体を一度実行します。代わりに通常の 'while()'ループを試してください。 – Dmitri
ピラミッドは負の高さを持つことができないことを忘れないでください。ピラミッドの高さは哲学的な難点です。 –
@JonathanLeffler:ビルドするのが最も簡単です! – usr2564301