0

When I try to compile my program I get this message "greedy.c:5:11: error: initializing 'float' with an expression of incompatible type 'float (void)' float y=GetFloat; ^ ~~~~~~~~" The carrot(I think that is what this is called^)is under the y

1
  • this is the code I am using #include<stdio.h> #include<stdio.h> #include<cs50.h> int main(void){ float y=GetFloat; //int amount; int count=0; char x=true; while(y>0){ if(y>24){ y=y-25; count++; }else if(y>9){ y=y-10; count++; }else if(y>4){ y=y-5; count++; }else if(y<0){ y=y-1; count++; }else{ printf("You have %d coins",count); x=false;} } } – zanderj Nov 18 '14 at 22:19
3

The function GetFloat from the CS50 library takes no arguments. The way you call it is as follows

GetFloat(); // NOTICE the empty parentheses

If you wanna assign the result returned by GetFloat to a float variable, you may do it that way

float f = GetFloat();

If you're curious about why the compiler gives you this error message, this is because a name of a function without the parentheses is treated as a pointer to a function. The compiler thinks you're trying to assign a pointer to a function to a variable of type float which is clearly a violation of the type-checking rules.

If you haven't got to pointers yet, just don't worry about that!

2
  • but I can not get it to work! – zanderj Nov 18 '14 at 22:04
  • I fixed that but when I input 0.26 it just says You have 0 coins and repeats forever (I excepted your answer by the way) – zanderj Nov 18 '14 at 22:42

You must log in to answer this question.

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