CS50检查器坏了还是我做错了什么?

时间:2016-10-15 06:18:53

标签: c cs50

编辑:在实施您的建议后,我已经解决了问题。非常感谢!

以下是检查结果的链接: https://sandbox.cs50.net/checks/9566a7b3d7094b108d3e6d6a03beaebc

即使预期的输出与我的输出匹配,它也表示没有。

另外,即使它输入'1'时没有换行,当我在终端尝试时,它确实如此。

如果你愿意,这是代码。非常感谢。

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

int main(void)

{
    int n;

    do
    {
        printf ("Please put in a positive number no larger than 24.");
        n = GetInt();
    }
    while (n < 0 || n > 23);

    for (int rownumber = 0; rownumber < n; rownumber++)
    {
        printf ("\n");
        int numberofspaces = n - rownumber - 1;
        int numberofhashes = rownumber + 2;
        do
        {
            printf (" ");
            numberofspaces --;
        }
        while (numberofspaces >= 0);
        do
        {
            printf ("#");
            numberofhashes --;
        }
        while (numberofhashes > 0);
    }
}

编辑:我根据您的建议进行了更改,但是,我仍然遇到同样的错误。这是新代码:

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

int main(void)

{
    int n;

    do
    {
        printf ("Please put in a positive number no larger than 24.");
        n = GetInt();
    }
    while (n < 0 || n > 23);

    for (int rownumber = 0; rownumber < n; rownumber++)
    {
        printf ("\n");
        int numberofspaces = n - rownumber - 1;
        int numberofhashes = rownumber + 2;
        while(numberofspaces > 0)
        {
        printf (" ");
        numberofspaces --;
        }       
        while (numberofhashes > 0) {
            printf ("#");
            numberofhashes --;
        }
    }
}

重新提交后指向新错误页面的链接: https://sandbox.cs50.net/checks/17185863c77d4c8cbafbddd0359d4035

1 个答案:

答案 0 :(得分:0)

使用var txt = @"<Commands> <Command command=""!command1"" response=""response1"" author=""niccon500"" count=""1237""/> <Command command=""!command2"" response=""response2"" author=""niccon500"" count=""1337""/> <Command command=""!command3"" response=""response3"" author=""niccon500"" count=""1437""/> </Commands>"; CommandListXml commands; using (var reader = new StringReader(txt)) { var serializer = new XmlSerializer(typeof(CommandListXml)); commands = (CommandListXml)serializer.Deserialize(reader); } 循环,循环中的代码保证至少执行一次,因为您在最后检查条件。
在这种情况下,正常do...while循环更好。

while