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

int main (void) {
    printf ("Please enter the change owed:"); 
    float amount = GetFloat(); 

    if (amount < 0) {
        printf ("Please enter a positive integar for the change"); 
    }

    float amountInCents = round(amount * 100); 

    if (amountInCents > 25) {
     float Quater_Coins = amountInCents % 25;
     printf("Number of $0.25 coins used = %f", Quater_Coins); 
 }


}

I keep getting this error:

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow    greedy.c  -lcs50 -lm -o greedy
**greedy.c:16:41: error: invalid operands to binary expression ('float' and 'float')
float Quater_Coins = amountInCents % 25;
                     ~~~~~~~~~~~~~ ^ ~~** 1 error generated. make: *** [greedy] Error 1
2

The % operator only works with integers, so you'll want to convert your float to an integer. That's kind of the purpose of round(), to round off the float so it can be applied to an int variable.

1

You must log in to answer this question.

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