CS50x Mario

From problem set 1. Both less and more versions.

Photo by Cláudio Luiz Castro on Unsplash
$ ./mario
Height: -1
Height: 0
Height: 42
Height: 50
Height: 4
#
##
###
####
~/ $ mkdir pset1 (only if you don't yet have the folder)
~/ $ cd pset1
~/pset1/ $ mkdir mario
~/pset1/ $ cd mario
~/pset1/mario/ $ touch mario.c
~/pset1/mario/ $ open mario.c
// Prompt user for a height value
// Make sure value is valid
// Draw pyramid
#include <stdio.h>
#include <cs50.h>
int getValue();
void draw(int height);
int main (void)
{
int height = getValue();
draw(height);
}
int getValue()
{
int a;
do
{
a = get_int("Height: ");
}
while (a < 1 || a > 8);;

return a;
}
void draw(int height)
{

}
$ make mario

$ ./mario
Height: -1
Height: 0
Height: 42
Height: foo
Height: 4
for (int row = 0; row < height; row++)
{
for (int spaces = row + 1; spaces < height; spaces++)
{
printf(" ");
}

for (int hashes = height + row + 1; hashes > height; hashes--)
{
printf("#");
}
printf("\n");
}
Results generated by style50 v2.7.4
Looks good!
Results for cs50/problems/2020/x/mario/less generated by check50 v3.1.2
:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) rejects a height of 0
:) handles a height of 1 correctly
:) handles a height of 2 correctly
:) handles a height of 8 correctly
:) rejects a height of 9, and then accepts a height of 2
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""
$ ./mario
Height: -1
Height: 0
Height: 42
Height: foo
Height: 4
# #
## ##
### ###
#### ####
printf("  ");

for (int hashes = height + row + 1; hashes > height; hashes--) {
printf("#");
}
Results for cs50/problems/2020/x/mario/more generated by check50 v3.1.2
:) mario.c exists
:) mario.c compiles
:) rejects a height of -1
:) rejects a height of 0
:) handles a height of 1 correctly
:) handles a height of 2 correctly
:) handles a height of 8 correctly
:) rejects a height of 9, and then accepts a height of 2
:) rejects a non-numeric height of "foo"
:) rejects a non-numeric height of ""