C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 18th, 2012, 12:46 PM
Mukilab Mukilab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Mukilab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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>

Reply With Quote
  #2  
Old November 18th, 2012, 12:55 PM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
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]

Reply With Quote
  #3  
Old November 18th, 2012, 12:57 PM
Mukilab Mukilab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Mukilab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old November 18th, 2012, 01:01 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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!

Reply With Quote
  #5  
Old November 18th, 2012, 01:05 PM
Mukilab Mukilab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Mukilab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old November 18th, 2012, 01:07 PM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
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.

Reply With Quote
  #7  
Old November 18th, 2012, 01:10 PM
Mukilab Mukilab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Mukilab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old November 18th, 2012, 01:21 PM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
You have an extra semicolon

int main(void); <=== THIS SEMICOLON IS WRONG
{

Reply With Quote
  #9  
Old November 18th, 2012, 01:26 PM
Mukilab Mukilab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Mukilab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #10  
Old November 18th, 2012, 02:19 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Mario problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap