Here is my code :
#include <stdio.h>
#include <cs50.h>
int main()
{
int height = -1;
int line = 0;
int counter = 0;
do
{
printf("Enter the height: ");
scanf("%d", &height);
}
while (height < 0 || height > 23);
printf("\n");
for(line = 1; line <= height; line++)
{
int spaceNum = height - line;
int spaceCounter = 1;
for (spaceCounter = 0; spaceCounter < spaceNum ; spaceCounter++)
printf(" ");
for(counter = 0; counter <= line ; counter++)
printf("#");
printf("\n");
}
return 0;
}
I think the program is working except the fact that when I enter 0 it does not ask me for an other number and I can't understand why. On top of that, when I check the program with the CS50 check, it seems as many flaws appear as you can see below:
:) 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 ##\n ..."
:( rejects a height of 24
\ expected output, but not "\n ##\n ..."
:( rejects a non-numeric height of "foo"
\ killed by server
:( rejects a non-numeric height of ""
\ expected output, not a prompt for input
https://sandbox.cs50.net/checks/b7b2820d825d43e0a44c32457d05fcd4
I can't see how to fix it; could anyone help ?
Kind regards,
Antoine Zerbini