Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
C#
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.



C#
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



CS50 OUTPUTS:



THanks a lot,

What I have tried:

C#
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");
    }

}
Posted
Updated 27-Dec-16 7:14am
Comments
[no name] 27-Dec-16 12:36pm    
Learning to use the debugger is STILL a valuable skill to learn.

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.
 
Share this answer
 
Comments
[no name] 27-Dec-16 14:57pm    
Countered
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.
 
Share this answer
 
Comments
[no name] 27-Dec-16 14:57pm    
And countered
Patrice T 27-Dec-16 18:15pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900