0

$ clang cash.c /tmp/cash-94cd4e.o: In function main': cash.c:(.text+0x1c): undefined reference to get_float' cash.c:(.text+0x44): undefined reference to `round' clang: error: linker command failed with exit code 1 (use -v to see invocation)

What does this mean?

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

int main (void)

{ float dollar;

  do

{ dollar=get_float("Enter your cahnge"); }

  while (dollar<=0);

int cents= round (dollar*100); int coins=0;

  while (cents>=25)

{ cents-=25; coins++; }

    while (cents>=10)

{ cents-=10; coins++; }

 while (cents>=5)

{ cents-=5; coins++; }

 while (cents>=1)

{ cents-=1; coins++; }

 printf ("You will need at least %i coins", coins);

}

0

First thing is probably try putting the #include statements on seperate lines. You have

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

Instead try

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

Compilers might complain that there are extra tokens at end of the top level directives.

Second thing, trying using

make cash

instead of using clang as you mightn't have linked up all the necessary header files. If you run make you'll be able to see the clang command with all the required necessary switches and settings you'll need to use if you do it manually.

0

get_float is not recognized by the compiler. The previous poster is right, put the #include in seperate lines. Did that fix it for you?

Same with round(), I think that's in the math.h library.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .