0

Below code is my attempt to solve Mario(More). However i do receive error when i use check50 cs50/2017/x/mario/more .I have saved my file and compiled it again. Also submitted the file to cs50.me and tried to use check50 still the same error.

Code for mario.c

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

void buildsteps(char c, int i);
void buildspaces(int height,int i);

int main(void)
{
    int height;

    do
    {
        printf("Height: ");
        height = get_int();

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

    for(int i=0; i<height;i++)
    {
        buildspaces(height,i);
        buildsteps('#',i);
        printf(" ");    //Extra step for mario.c more
        buildsteps('#',i);  //Extra step for mario.c more
        printf("\n");
    }
}

void buildsteps(char c, int i)
{
    for(int j=0; j<=i; j++)
    {
        printf("%c",c);  
    }
}

void buildspaces(int height,int i)
{
    for(int k=height; k>i+1; k--)
    {
        printf(" ");
    }    
}

Error

:( handles a height of 1 correctly
expected "# #\n", not "# #\n" 

Log 
running ./mario... 
sending input 1... 
:( handles a height of 2 correctly
expected " # #\n## ##\n", not " # #\n## ##\n" 

Log 
running ./mario... 
sending input 2... 
:( handles a height of 23 correctly
expected " ...", not " ..." 

Log 
running ./mario... 
sending input 23... 
:( rejects a height of 24, and then accepts a height of 2
expected " # #\n## ##\n", not " # #\n## ##\n" 

Log 
running ./mario... 
sending input 24... 
checking that input was rejected... 
sending input 2... 
checking for output " # # ## ## "... 

Kindly let me know what am i doing wrong. Even from check50 the excepted and received code are same.

Thank You

1

There should be two blanks in the middle, not one.

| improve this answer | |
  • thank you very much. That indeed was the problem – Saran Aug 2 '17 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .