Advertisement
noob339

Untitled

Oct 6th, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. void printNumCharacter (int spaces, char character) //function that formats the characters
  6. {
  7.     for (int i = 0; i < spaces; i++) //loop to help format the characters based on width
  8.     {
  9.         printf("%c", character); //allows us to print the character we choose later on
  10.     }
  11. }
  12.  
  13. void drawOneRow(int rowNum, int width, char c1, char c2){ //function allows us to choose our characters and print function parameters from above
  14.     //loop will go here (just realized we never wrote a loop here)
  15.     int numSpaces = width - rowNum - 1; // stores the number spaces or any characters but takes the width and subtracts one char/space for every row
  16.    
  17.     int hash = 1 + rowNum; // stores the number of hashes/any char but adds one more char for every row
  18.    
  19.     printNumCharacter(numSpaces, c1); //calls the function from above to format the spaces/any char
  20.    
  21.     printNumCharacter(hash, c2); //calls function to format the hashes/any char
  22.    
  23.     printf(" "); // for the column of space
  24.    
  25.     printNumCharacter(hash, c2); //calls function to format the hashes/any char after the column
  26. }
  27. /*void drawOneRowEasy(int rowNum, int width, char c1, char c2){ //this is the function for the easy version without the space
  28.    
  29.     int numSpaces = width - rowNum - 1; //same as above
  30.     int hash = 1 + rowNum; // same as above
  31.     printNumCharacter(numSpaces, c1); //will format the spaces and the hashes
  32.     printNumCharacter(hash, c2); // will format the hashes and then spaces
  33. }*/
  34.  
  35. int main(void){ // this is our main function
  36.    
  37.     int h; //declare a variable
  38.     h = get_int("Width: "); //ask for user input
  39.    
  40.     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
  41.     {
  42.         //// 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
  43.         drawOneRow(i,h,'1','2');
  44.         printf("\n");  //breaks line after every row
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement