CS50 Mario(更舒适)错误信息

问题描述 投票:0回答:1

我的代码出了什么问题?我正在收到这些消息(悲伤的面孔是错误):

:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:( handles a height of 0 correctly
   \ expected an exit code of 0, not output of "  \n"
:( handles a height of 1 correctly
   \ expected output, but not "   \n#  #\n"
:( handles a height of 2 correctly
   \ expected output, but not "    \n #  #\n##  ##\n"
:( handles a height of 23 correctly
   \ expected output, but not "                         \n            ..."
:) rejects a height of 24    
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""

该程序似乎工作正常,而不是CS50正在寻找的方式。

#include <stdio.h>
#include <cs50.h>

int main(void) {
    int height;
    int i;

    do {
        printf("Height:");
        height = get_int();
    }while(height < 0 || height > 23);

    int x = height;
    int y = 0;

    for (i = 0; i < height + 1; i++)
    {
        for (i = 0; i < x; i++)
        {
            printf("%s", " ");
        }

        for (i = 0; i < y; i++)
        {
            printf("#");
        }

        printf("%s", "  ");

        for (i = 0; i < y; i++)
        {
            printf("#");
        }

        printf("\n");
        x = x - 1;
        y = y + 1;
    }
    return 0;
}
c cs50
1个回答
0
投票

在用户输入高度后尝试包含if语句。这将至少为你获得0的高度的正确结果。

if (height == 0)
{
    return 0;
}

这些/消息是修复代码的关键。你有这个。

© www.soinside.com 2019 - 2024. All rights reserved.