0

Something's wrong with my function declarator, and i have a different error that I don't understand at all. Please help!

Here is the code:

#include <stdio.h>
#include <cs50.h>

int n;

int main(void)
{

do
{
    printf("How many blocks would you like Mario to jump?\n");
    n = GetInt();
    printf("Height: %i\n", n);

}
while (n < 1 || n > 23);


//create pyramid

    for (int i = 0; i < n; i++)

    for (int j = 0; j < n; j++)

    printf("%d\n", j);

    for (int k = n; k < n + 2; k++)

    printf("#");

    printf(" \n");

return (0);
}
0

Not sure why you are scared of the {}... although it makes sense to you, it is more clear to others reading your code. this looks much better imo.

//create pyramid

for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
        {
        printf("%d\n", j);
        }
    for (int k = n; k < n + 2; k++)
        {
        printf("#");
        }
printf(" \n");
}

this still isnt right but maybe you can see better what is happening. remember you want to 1.print spaces 2.print hashes 3.increment values of spaces and hashes 4.loop till you have your height. You are getting closer my friend. i will point out that the \n in your first nested for loop shouldnt be there.print you num of spaces, print your num #'s then \n like you have at bottom. Hope this gets you closer. :D

12
  • I did it and fixed those errors, but now something's wrong with my GetInt function. I'll edit my post to show the new code – Elephant1123 May 2 '16 at 22:02
  • Sorry man "problem with getint" is vary vague. What is happening when you run the program? – Firecore May 2 '16 at 22:20
  • GetInt is a function from the cs50.h library. So you need to #include <cs50.h>. That will fix that problem. after that you will find your program will have more issues. You should back up and watch the videos of functions and loops. your for loops have have to { }. Not sure why you are printing 'a'. I suggest revisiting for loops and including the cs50 header file. try again and we can go from there. don't want to do it for you but willing to guide you :D – Firecore May 3 '16 at 1:49
  • The for loops work fine with parens, and I can compile now that I added the header without any errors, but the construction of my pyramid is off. I get this output, for example, when I enter 3: Height: 3 {next line} 0 {next line} 1 {next line} 2 {next line} 0 {next line} 1 {next line} 2 {next line} 0 {next line} 1 {next line} 2 {next line} ##. Thoroughly confused. I'll edit the initial post to show the new code. – Elephant1123 May 5 '16 at 0:33
  • edited the answer above Elephant1123 – Firecore May 5 '16 at 1:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .