Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- void printNumCharacter (int spaces, char character) //function that formats the characters
- {
- for (int i = 0; i < spaces; i++) //loop to help format the characters based on width
- {
- printf("%c", character); //allows us to print the character we choose later on
- }
- }
- void drawOneRow(int rowNum, int width, char c1, char c2){ //function allows us to choose our characters and print function parameters from above
- //loop will go here (just realized we never wrote a loop here)
- int numSpaces = width - rowNum - 1; // stores the number spaces or any characters but takes the width and subtracts one char/space for every row
- int hash = 1 + rowNum; // stores the number of hashes/any char but adds one more char for every row
- printNumCharacter(numSpaces, c1); //calls the function from above to format the spaces/any char
- printNumCharacter(hash, c2); //calls function to format the hashes/any char
- printf(" "); // for the column of space
- printNumCharacter(hash, c2); //calls function to format the hashes/any char after the column
- }
- /*void drawOneRowEasy(int rowNum, int width, char c1, char c2){ //this is the function for the easy version without the space
- int numSpaces = width - rowNum - 1; //same as above
- int hash = 1 + rowNum; // same as above
- printNumCharacter(numSpaces, c1); //will format the spaces and the hashes
- printNumCharacter(hash, c2); // will format the hashes and then spaces
- }*/
- int main(void){ // this is our main function
- int h; //declare a variable
- h = get_int("Width: "); //ask for user input
- for (int i = 0; i < h; i++) //loop where it'll call a function as long as i is less than h and while its true the lines below will execute
- {
- //// i will go up while i < h is true creating several rows, h takes the user input in, the next two parameters takes in the charcters you want
- drawOneRow(i,h,'1','2');
- printf("\n"); //breaks line after every row
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement