Timeline for Help with Mario - expected expression/identifier
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 30, 2018 at 15:25 | comment | added | Blauelf |
There's that difference between function declaration (telling the compiler what a function looks like, so it can work with the name without having the code yet) and function definition (the actual implementation). In header files (.h files), you'd have declarations of all the functions you want to have available externally, but in the .c file you would define the functions. Also, internally used declarations may go to the top of a .c file, so the order of the function definitions below doesn't matter.
|
|
Jan 30, 2018 at 15:01 | vote | accept | Michael Syring | ||
Jan 30, 2018 at 15:01 | comment | added | Michael Syring | Thank you! I am seriously struggling with the syntax on this stuff, and I know I took that out at one point, but probably had something else wrong and ended up putting it back in. I looked at other code that did have it in there, but I am assuming they didn't get to the point of compiling yet and didn't take it out. Thanks for your help and patience! | |
Jan 30, 2018 at 14:51 | comment | added | Blauelf |
You have created Frankenstein's monster from a function declaration and a function definition, creating broken code. Remove semicolon after int main(void) .
|
|
Jan 30, 2018 at 14:00 | comment | added | Michael Syring | yes, it's there, but I am still getting the error at line 8. I have only written 16 lines of code and can't get past this. Please help! Here is my code: #include <stdio.h> #include <cs50.h> int main(void); { int h; do { h = get_int("Height of Pyramid: "); } while (h<0 || h>23); } | |
Jan 29, 2018 at 22:05 | comment | added | Blauelf |
If you create the variable within the loop, it exists only for the current iteration, and will cease to exist before the loop condition is reached. You are missing the semicolon after while (h < 0 || h > 23) . And there's no way to do multi-line in comments. BTW, you just did not post the int main(void) part, but it's there, right?
|
|
Jan 29, 2018 at 19:40 | comment | added | Michael Syring | That's super hard to read, but I'm not sure how to get my code to indent in a comment, sorry. | |
Jan 29, 2018 at 19:39 | comment | added | Michael Syring | I am so frustrated. I found other sites thay say the same thing. When I implement it, it doesn't work! What am I doing wrong?!?! From a site: 'do { statement(s) } while (boolean expression);' My code: '{ int h; do { h = get_int("Height of Pyramid: "); } while (h<0 || h>23) }' I have brackets after do, before while and my int is stated before it's used. Still I get the error... 'error: expected identifier or '(' { ^' what is it looking for when it says expected identifier?!? | |
Jan 29, 2018 at 19:11 | comment | added | Michael Syring | Thanks. I thought the int h after do was introducing the variable, which I guess make sense because you don't want to introduce it every iteration. What do you mean inside the main function, but also needing its own brackets? I think some of that terminology is not defined so well. I assume, leave the loop,means it ends the loop, is that correct? The do while loops are based on exclusive statements? I must have that backwards then. Seriously, this stuff is tough to wrap my head around. All the syntax and terminology is a struggle! Thanks for your help! | |
Jan 29, 2018 at 16:19 | history | answered | Blauelf | CC BY-SA 3.0 |