The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Mario problem
Discuss Mario problem in the C Programming forum on Dev Shed. Mario problem C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 18th, 2012, 12:46 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 49 m 8 sec
Reputation Power: 0
|
|
|
Mario problem
Hi I'm trying to create a code that creates a half-pyramid such as the end of mario based upon a height entered by a user.
I've started the basics, and I want to test it but I keep getting the problem
"mario.c:7:1: error: expected identifier or '('
{
^
1 error generated." any help??
Code would work like this:
User inputs height 8, but it would be RIGHT ALIGNED:
Code:
##
##
###
####
#####
######
#######
########
Here is the code, thanks for the help
Code:
#include <stdio.h>
#include <cs50.h>
int main(void);
{
printf("Please choose a positive integer for the height of Mario's pyramid\n");
/*int h is the height of the half-pyramid*/
int h = GetInt();
while (h=<0|| h >= 24);
{
for(int space = 9 - h; space < h; space++)
{
printf(" ");
}
for(int hash = h + 1; hash < h; hash++)
{
printf("#");
}
printf("\n")
}
else
{
printf("Please choose a number between 1 and 23\n");
int h = GetInt();
}
}
The GetInt is a function to get an integer and works with <cs50.h>
|

November 18th, 2012, 12:55 PM
|
|
|
|
There is no operator =< in C. You probably want <=.
You have an extra semicolon after the while condition, effectively turning the loop into an infinite loop (and creating a free brace delimited code block).
You have a dangling else in your code.
[Edit]Using code tags helps us examine your code and better help you.[/Edit]
|

November 18th, 2012, 12:57 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 49 m 8 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by bdb There is no operator =< in C. You probably want <=.
You have an extra semicolon after the while condition, effectively turning the loop into an infinite loop (and creating a free brace delimited code block).
You have a dangling else in your code.
[Edit]Using code tags helps us examine your code and better help you.[/Edit] |
Thank you, what do you mean by a dangling else?
I still have the error error: expected identifier or '('
{
^
though
|

November 18th, 2012, 01:01 PM
|
 |
Contributing User
|
|
|
|
|
Search your program for "if"
Search your program for "else"
(there is an else, there are no ifs.)
if precedes else otherwise syntax error.
__________________
[code] Code tags[/code] are essential for python code!
|

November 18th, 2012, 01:05 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 49 m 8 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by b49P23TIvg Search your program for "if"
Search your program for "else"
(there is an else, there are no ifs.)
if precedes else otherwise syntax error. |
Thank you, I was under the impression there was a while-else statement.
Still getting the error though
error: expected identifier or '('
{
^
1 error generated.
|

November 18th, 2012, 01:07 PM
|
|
|
Quote: | Originally Posted by Mukilab I still have the error error: expected identifier or '('
{
^
though |
It would help a bit if you identify the line in question (I noticed a message saying line 7: "int h = GetInt();").
Are you using a C89 compiler (notably Microsoft's Visual Studio)?
In C89 you cannot have declarations and code intermixed.
Line 6 is code; line 7 is a declaration (definition with initialization).
Swap lines 6 and 7.
|

November 18th, 2012, 01:10 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 49 m 8 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by bdb It would help a bit if you identify the line in question (I noticed a message saying line 7: "int h = GetInt();").
Are you using a C89 compiler (notably Microsoft's Visual Studio)?
In C89 you cannot have declarations and code intermixed.
Line 6 is code; line 7 is a declaration (definition with initialization).
Swap lines 6 and 7. |
Hi, I am using a virtual engine which is running linux fedora. Not exactly sure what compiler I'm using unfortunately, it was more of a package thing, I didn't have to do too much work myself installing it.
By line do you mean mario.c:7:1: error:??? However this refers to line 9 in the code I posted since my original code has two lines extra on the top.
Specifically it refers to { after int main(void) although what could possibly be wrong with that?
Specifically as in assuming that mario.c:7:1: refers to line 7
|

November 18th, 2012, 01:21 PM
|
|
|
|
You have an extra semicolon
int main(void); <=== THIS SEMICOLON IS WRONG
{
|

November 18th, 2012, 01:26 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 49 m 8 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by bdb You have an extra semicolon
int main(void); <=== THIS SEMICOLON IS WRONG
{ |
fantastic! thanks
|

November 18th, 2012, 02:19 PM
|
 |
Contributing User
|
|
|
|
|
Where a compiler indicates trouble is often caused by a mistake appearing earlier in the program.
The compiler reads more code than you might think it ought to because it tries hard to follow all the possible parse rules.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|