Hi!
So first of all, please keep in mind that I have just began with C, I took CS50x from Harvard and so far I have a very limited knowledge, so my question may seem very simple.
What I have to do is to create a "pyramid" which has to look something like this:
The user has to firstly input an integer to declare how many rows the pyramid is going to have.Code:# ## ### ####
What I have so far
What I am struggling with currently is to figure out how to print out space (h - 1) timesCode:#include <stdio.h> #include <cs50.h> #include <math.h> int main(void) { //create an infinite loop that will check the value while (1) { //get an integer from the user which will define the height of the pyramid printf("Enter the height of the pyramid! The value has to be in range 3 to 24.\n"); int h = GetInt(); //if a value is in the range, then proceed to create a pyramid if (h<=24 && h >= 3) { for(int i = h; i > 0; i--) { printf("row\n"); } break; } //otherwise continue loop and ask for an another value else { printf("You have entered the invalid value, please try again.\n"); } } return 0; }
I would really appreciate any help, but rather then just giving me a finished code I would appreciate a "guidance". Thank you



LinkBack URL
About LinkBacks




