0
我目前在做CD50在線課程,並且遇到了循環問題。我知道它從0開始。我認爲這就是拋棄我的原因。C語言中的循環以及如何正確使用它
我的任務是用用戶給出的數字創建「Mario」步驟。 How it should look
我試圖在1,而不是0 開始循環來解決這個問題,但我寧願明白如何正確地做到這一點。
int height;
string hash = "#";
string empty = " ";
do
{
printf("Height: ");
height = GetInt();
}
while (height > 23 || height <= 0);
{
printf("Height = %i\n", height);
for (int step = 0; step < height; step++)
{
for(int spaceNumber = height; spaceNumber >= step; spaceNumber--)
{
printf("%s",empty);
}
for(int hashNumber = 0; hashNumber <= step; hashNumber++)
{
printf("%s",hash);
}
printf("\n");
}
}
}
您在代碼中有幾個錯誤...的','後的第一個while循環表示你將永遠循環下去的條件爲真。 .. –