1. Problems with Mario Pyramide

Hey guys,

I recently started the cs50x course online and try to learn c because I haven't got any programming courses in school atm.

I don't want anyone here to solve the courses homework for me but I'm stuck with an error I don't really get...

The task was to get an integer from 1-23 from the user and then to build a pyramide like this:

height: 8
##
###
####
#####
######
#######
########
#########

So I wrote this code:
Code:
```#include <stdio.h>
#include <cs50.h>

int main()
{
int height = GetInt();

while (height < 1 || height > 23)
{
printf("Please enter a positive Integer not bigger than 23:\n");
height = GetInt();
}

for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
{

for(int leerzeichen = (height (+1 -b));leerzeichen > 0;leerzeichen--)
{
printf(" ");
}

for(int rauten = (height (+1 - c)); rauten > 0; rauten--)
{
printf("#");
}
printf("\n");

}

}```
But I get this goddamn error:

~/workspace/pset1 \$ make mario
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow mario.c -lcs50 -lm -o mario
mario.c:15:32: error: expected identifier or '('
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
mario.c:15:32: error: expected ';' in 'for' statement specifier
mario.c:15:32: error: expected expression
mario.c:15:68: error: expected ')'
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
~/workspace \$ make mario
make: *** No rule to make target `mario'. Stop.
~/workspace \$ cd pset1
~/workspace/pset1 \$ make mario
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow mario.c -lcs50 -lm -o mario
mario.c:15:32: error: expected identifier or '('
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
mario.c:15:32: error: expected ';' in 'for' statement specifier
mario.c:15:32: error: expected expression
mario.c:15:68: error: expected ')'
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
mario.c:15:8: note: to match this '('
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
mario.c:15:64: error: relational comparison result unused [-Werror,-Wunused-comparison]
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
~~~~~~~~^~~
mario.c:15:70: error: use of undeclared identifier 'height2'; did you mean 'height'?
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^~~~~~~
height
mario.c:7:9: note: 'height' declared here
int height = GetInt();
^
mario.c:15:82: error: use of undeclared identifier 'b'
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
mario.c:15:88: error: use of undeclared identifier 'c'
for(int height2 = height , int b = 2 , int c = 6 ; height2 > 0 ; height2-- , b++ , c--)
^
8 errors generated.
make: *** [mario] Error 1

It would be great if you could help me, because I really don't know
what the hell I did wrong

Lovely greetings from Germany,
Polarsturm (Johannes)

2. You have too many "int"s in your for loop. Once you say int, that means all the new variables in your list are int:
Code:
`for (int height2 = height, b = 2, c = 6; height2 > 0; height2--, b++, c--)`
You are also limited to one type of variable in the for loop header. It doesn't matter if it's int, pointer, or something else, but you can only use one type.

Actually, pointers can get complicated, so here's an example:
Code:
```#include <stdio.h>

int main(void)
{
char text[] = "Example.";
for (char *ptext = text, *end = &text[8]; ptext < end; ptext++)
printf("%2x ", *ptext);
}```

3. Chua Me O! It's a lot trickier than you tink. The order is extremely important depending on the compiler you use. So for instance:

Code:
```char value;
value = 'A'```
if NOT the same like
Code:
```value = 'A'
char value```

4. Thank you both very very much!
I'm all new with programming and didn't know this

I had to do a few more changes but now I almost get it running how it should ^^

5. I don't know if anybody cares, but I'm a little bit proud I got it working, so here's the correct code ^^
I think that I'll can learn a lot from this forum

Code:
```#include <stdio.h>
#include <cs50.h>

int main()
{
int height = GetInt();

while (height < 1 || height > 23)
{
printf("Please enter a positive Integer not bigger than 23:\n");
height = GetInt();
}

for(int height2 = height , b = 2 , c = height +1 -2 ; height2 > 0 ; height2-- , b++ , c--)
{

for(int space = height +1 -b; space > 0; space--)
{
printf(" ");
}

for(int rauten = height +1 - c; rauten > 0; rauten--)
{
printf("#");
}
printf("\n");

}

}```

6. Jesus! Chua Me O! That's great. I don't understand it because my compiler spits out errors because I don't have the cs50 header. Also my compiler expects you to define everything upfront instead of as you go. But congratulations. I think people learn best when they are not pressured. You need room to experiment on your own time. Then again, others need structure and a routine or else they fall through the cracks............

7. A bit over engineered for my taste.
Code:
```void mario (int height)
{
int length = 2;
while (height-- > 0) {
int c;
for (c = 0; c < length; ++c) {
putchar('#');
}
putchar('\n');
++length;
}
}```

8. Thank you Tien Yes I'll definitely need some time to learn programming ^^

And whiteflags my version is indeed a bit over engineered
Why make it complicate if you can keep it short and simple.

9. Originally Posted by Polarsturm
Thank you Tien Yes I'll definitely need some time to learn programming ^^

And whiteflags my version is indeed a bit over engineered
Why make it complicate if you can keep it short and simple.
@Polarsturm: I'm no hotshot. Far from it. What I've learned is nothing compared to all the knowledges out there. I plan on keeping learning programming while I'm alive. Although my age has made me slow in learning these days I do actually read 1 page a day. I once heard old people tell me it is harder for them to study than when young. Now I see it is true. Back in the old days when I was just a kid I could study 5 textbooks (30 pages each) per book a day. Now I'm down to 1 on average per day. Serious. At least there is a theory that you can get it done by the time you pass if you keep at it. My real dad told me to be consistent and my real mom told me to keep working. So thank you to my real mom Huong Thi Thuyen Vu and to my real dad Nguyen Binh Thuy. My two sisters followed their advices and succeeded while I didn't and I'm way behind with outdated technology. Thank you Jesus Christ.