PSET 1黑客马里奥代码 [英] PSET 1 hacker mario code

查看:100
本文介绍了PSET 1黑客马里奥代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

The instructions are here: http://cdn.cs50.net/2016/x/psets/1/hacker1/hacker1.html#itsa_mario

and here for the full understanding of the basic requirements:

http://cdn.cs50.net/2016/x/psets/1/pset1/pset1.html#itsa_mario

The problem is I get the correct output but my code isnt correct.










Check50:

) mario.c exists

:) mario.c compiles

:) rejects a height of -1

:) handles a height of 0 correctly

:) handles a height of 1 correctly

:( handles a height of 2 correctly \ expected output, but not " # # \n## ##\n"

:( handles a height of 23 correctly \ expected output, but not " # # ..."

:) rejects a height of 24

:) rejects a non-numeric height of "foo"

:) rejects a non-numeric height of ""





我的产品







CS50输出:







谢谢很多,



我尝试了什么:





MY OUTPUTS



CS50 OUTPUTS:



THanks a lot,

What I have tried:

Hacker Mario

up vote
0
down vote
favorite
The instructions are here: http://cdn.cs50.net/2016/x/psets/1/hacker1/hacker1.html#itsa_mario

and here for the full understanding of the basic requirements:

http://cdn.cs50.net/2016/x/psets/1/pset1/pset1.html#itsa_mario

The problem is I get the correct output but my code isnt correct.

Check50:

) mario.c exists

:) mario.c compiles

:) rejects a height of -1

:) handles a height of 0 correctly

:) handles a height of 1 correctly

:( handles a height of 2 correctly \ expected output, but not " # # \n## ##\n"

:( handles a height of 23 correctly \ expected output, but not " # # ..."

:) rejects a height of 24

:) rejects a non-numeric height of "foo"

:) rejects a non-numeric height of ""

MY OUTPUTS My OUtputs

CS50 OUTPUTS Outputs of CS50 Staff implementation

Finally, my code:

{ int height; int i; int spaces1; int blocks1; int spaces2; int blocks2;

 do 
 {
    printf("Height: ");
    height = GetInt();
     if (height==0)
     {
         return 0;
     }

 }
 while 
 (height < 0 || height > 23);

if (height == 1)
{
    for (i=0; i<1;i++)
    {
        for (blocks1 = 0; blocks1 < 1; blocks1++)
        {
            printf("#"); 
        }

        printf("  ");

        for (blocks2 = 0; blocks2 < 1; blocks2++)
        {
           printf("#");   
        }

        printf("\n");
    }
}



else  
{
    for (int a=1; a<height +1; a++)
    {
        for(spaces1 = 0; spaces1 < height-a; spaces1++)
        {
            printf(" ");
        }

        for (blocks1 = 0; blocks1 < a; blocks1++)
        {
            printf("#"); 
        }

        printf("  ");

        for (blocks2 = 0; blocks2 < a; blocks2++)
        {
           printf("#");   
        }

        for(spaces2 = 0; spaces2 < height - a; spaces2++)
        {
            printf(" ");
        }

        printf("\n");
    }

}

推荐答案

你要么学会使用调试器,要么在你做之前,你将停止做这些挑战。



调试器可以调试你。它可以帮助您理解您编写的代码。计算机正在完成你告诉它要做的事情。每次都对代码的解释是死的。问题是你不明白你告诉它做什么。



你从调试器中学到了很多东西,而不是你在论坛,希望有人为你努力工作。
You're either going to learn to use the debugger or you're going to stop doing these challenges until you do.

The debugger is there to debug YOU. It's there to help you understand the code you've written. The computer is doing exactly what you've told it to do. It's interpretation of the code is dead on, every single time. The problem is that YOU don't understand what you've told it to do.

You learn a LOT more from the debugger than you EVER will dropping questions in a forum and hoping someone does the hard work for you.


你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码正在执行并确保它能达到预期的效果。



Debugger - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么以及您的任务是与它应该做的比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于PSET 1黑客马里奥代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆