Created
May 11, 2020 16:58
-
-
Save waynewallace/8ded877225439529df7ff21ef618fc9e to your computer and use it in GitHub Desktop.
Harvard C Assignment 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mario.c | |
// | |
// prints pyrimid block wall with stair step on both sides with valley of | |
// spaces in the middle | |
// | |
// Sample output | |
// | |
// Height: | |
// 4 | |
// # # | |
// ## ## | |
// ### ### | |
// #### #### | |
#include <cs50.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
int height; | |
// get user input | |
// valid input positive numbers between 1 and 8 inclusive | |
do | |
{ | |
height = get_int("Height:\n"); | |
} | |
while (height < 1 || height >= 9); | |
// print rows of the wall | |
for (int rowCount = 1; rowCount <= height; rowCount++) | |
{ | |
// add spaces as needed to each row | |
for (int spacesToAdd = 0; spacesToAdd <= height; spacesToAdd++) | |
{ | |
if (rowCount < spacesToAdd) | |
{ | |
printf(" "); | |
} | |
} | |
// print half the row of # blocks | |
for (int blockCount = 0; blockCount < rowCount; blockCount++) | |
{ | |
printf("#"); | |
} | |
// print the space in between | |
printf(" "); | |
// print the other half the row of # blocks | |
for (int blockCount = 0; blockCount < rowCount; blockCount++) | |
{ | |
printf("#"); | |
} | |
// print end of line return | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment