i'm trying to fix this error :

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 3083 Views - Last Post: 26 November 2012 - 12:49 AM Rate Topic: -----

#16 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:55 AM

Well...there won't be much use of getInt here as you will be once again initializing your height to 1 in your for loop.So you can remove getInt() altogether.

But, for your learning purpose, here is how to define the getInt function.

int getInt()
{
  int h;
  printf("please choose a positive integer for the height of Mario's pyramid   less then 24 \n"); 
  scanf("%d",&h);

  return h;
}


regards,
Raghav

This post has been edited by raghav.naganathan: 24 November 2012 - 01:56 AM

Was This Post Helpful? 1
  • +
  • -

#17 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 01:59 AM

/tmp/mario2-5CGiQP.o: In function `main':
mario2.c:(.text+0x33): undefined reference to `GetInt'
clang: error: linker command failed with exit code 1 (use -v to see invocation) [err_drv_command_failed]
Was This Post Helpful? 0
  • +
  • -

#18 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 02:00 AM

Can you post the exact code which gave you the above errors?

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#19 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 02:02 AM

thanks alot man :D and please keep in touch
Was This Post Helpful? 0
  • +
  • -

#20 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 02:04 AM

Well, you're welcome...:)

Did you solve the problem you had?

regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#21 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: i'm trying to fix this error :

Posted 24 November 2012 - 02:13 AM

From the error message - that was GetInt() call in main(). No such function, since yours was named getInt() ;)

OP, remember - C is case sensitive.
Was This Post Helpful? 1
  • +
  • -

#22 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 24 November 2012 - 02:17 AM

Nice catch there Xupicor, I am used to naming my functions like small-letter at the start, so I guess I assumed it to be getInt() ;)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#23 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 25 November 2012 - 10:39 PM

thanks FOR UR NOTE BUT IT SHOULD TO BE: GetInt() and i work on my code ....and i still have errors .... but for me it's my first code so i feel bad.... i miss something in that ... i use paper and pen .... i read and watch videos but i dunno .....see the code:
#include <stdio.h>
#include <cs50.h>

int main (void)
{
    int hash, space,height;              
        
   do
{
         height= GetInt();   
      while (height=1; height <=23) ;
         }  
   
   for (  space =  height-1 ; space <= 0; space++)
   
    {            printf(" ");                 }      

   for (  hash =  height+1 ; hash >= 2 ; hash++)
   
     {               printf(" # ");                     }
                       
}

This post has been edited by JackOfAllTrades: 26 November 2012 - 04:11 AM
Reason for edit:: Added code tags

Was This Post Helpful? 0
  • +
  • -

#24 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 25 November 2012 - 11:09 PM

Well, one thing...since you are using int main(), you need to return 0.

Also, the GetInt() function needs to be defined for it to be used here.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#25 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 25 November 2012 - 11:32 PM

GetInt it's include in cs50.h and even if i return 0 that's make 1 more error :
o2.c:11:14: error: use of undeclared identifier 'height'
while (height=1; height <=23)
^
mario2.c:11:24: error: use of undeclared identifier 'height'
while (height=1; height <=23)
^
mario2.c:14:7: error: expected 'while' in do/while loop
for (space = height-1 ; space <= 0; space++)
^
mario2.c:8:9: note: to match this 'do'
do
^
mario2.c:24:4: error: expected identifier or '('
return 0;
^
4 errors generated.
Was This Post Helpful? 0
  • +
  • -

#26 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 25 November 2012 - 11:41 PM

You need to declare height variable before initialization and in the while loop, only use the condition and not the initialization.

and you have used while in the loop of the do-while

it should be
do
{
//code
}while(condition);


regards,
Raghav

This post has been edited by raghav.naganathan: 25 November 2012 - 11:42 PM

Was This Post Helpful? 1
  • +
  • -

#27 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 25 November 2012 - 11:45 PM

can u explain to me do while loop more if u don't mind ?





#include <stdio.h>
#include <cs50.h>

int main (void)
int height;int hash;int space
{
                 
        
        do
{
        //    int  height= GetInt();   
      while(int height=1; height <=23;height++) 
}  
   
      for  (int space =   height-1 ; space <= 0; space++)
{   
                printf(" ");                       
}
      for (  hash =  height+1 ; hash >= 2 ; hash++)
{  
                    printf(" # ");                     
}                       
}           
         
   return 0;

This post has been edited by JackOfAllTrades: 26 November 2012 - 04:10 AM
Reason for edit:: Added code tags

Was This Post Helpful? 0
  • +
  • -

#28 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 25 November 2012 - 11:50 PM

Sure...a do-while loop will execute at least once in your entire program.

Eg.

int i=0;
do
{
printf("Execute once");
}while(i>0);


You will see that the condition in while is false, but no matter what the condition is, the printf will be executed at least once.

In your program as well, you need to use the while outside the do loop.

regards,
Raghav
Was This Post Helpful? 1
  • +
  • -

#29 jossef  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 15
  • Joined: 23-November 12

Re: i'm trying to fix this error :

Posted 26 November 2012 - 12:22 AM

sir did u mind to teach me c language ?!!
i'm really can't understand why i can't draw a pyramid with height between 1 and 23 using hash align with left side of the screen ??
Was This Post Helpful? 0
  • +
  • -

#30 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: i'm trying to fix this error :

Posted 26 November 2012 - 12:49 AM

View Postjossef, on 26 November 2012 - 12:52 PM, said:

sir did u mind to teach me c language ?!!
i'm really can't understand why i can't draw a pyramid with height between 1 and 23 using hash align with left side of the screen ??


Well, I so wish to but unfortunately I am a working guy and got a lot of responsibilities in my office including a new project. I would suggest you take a look at some books which will teach you C...the ones which explain C in a very simplified manner.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2