0

So complete rookie i saw functions from other peoples code n stuff

#include <stdio.h>
#include <cs50.h>
int main(void)
{
    int h, i, s, k;
    //get user input and follow limitations
    do {
        printf("height: ");
        h = GetInt();
    } while ((h < 0) || (h > 23));

    //start one counter to end printing after achieving height
    //second conter (s) for spaces on individual lines
    //third counter (k) for hashes/sharps
    //then print new line

    for (i = 0, i <= h, i++);
    {
        for (s = 0, s < (h - i - 1), s++);
        {
            printf(" ");
        }
        for (k = 0, k < (i + 2), k++);
        {
            printf("#");
        }
        printf("\n");
    }
    return(0);
}

and then an overwhelming response of 12 errors mainly for for condition and it's semi colon and loop breaker condition and pretty sure more to come please help this is getting scary

1
  • You don't have to close your question just because it was answered/solved. Leave it for reference for the next person having the same problem.
    – ChrisG
    Commented Aug 21, 2016 at 11:52

1 Answer 1

2

All are simple syntax errors. Let's look at one of your for statements:

for(i=0,i<=h,i++);

A for loop setup statement has 3 clauses, the initialization clause, the test clause, and the incrementation clause. These clauses are separated by semicolons. You chose to try to separate them with commas.

Next, the for loop setup statement is followed by either a block of code enclosed in a curly brace pair, or a single statement ending with a semicolon. You have done the latter. By not having any code between the closing parenthesis and the semicolon, you have created a for loop that does nothing h+1 times (assuming it didn't have the previous problem).

Spend some time reviewing the proper construction of a for loop and try again.

If this answers your question, please click on the check mark to accept. Let's keep up with forum maintenance. ;-)

3
  • hey so i changed to semi colons and emoved later ones but i am rejecting all positive numbers
    – Tejas D
    Commented Aug 21, 2016 at 9:43
  • :( handles a height of 0 correctly \ expected an exit code of 0, not output of "height: " :( handles a height of 1 correctly \ expected output, but not "##\n###\n" :( handles a height of 2 correctly
    – Tejas D
    Commented Aug 21, 2016 at 9:43
  • If a height of 0 is given you should print a pyramid with 0 height, so nothing, not repeat the input process.
    – ChrisG
    Commented Aug 21, 2016 at 11:51

You must log in to answer this question.

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