1

so I used check50 on my code and it said 1.6, 23, and 4.2 had a wrong output. Can you please help me to see what I am doing wrong? Here is my code:

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

int main(void)
{
    float dollars;
    do
    {
      dollars = get_float("Enter change owed:");
    } while (dollars < 0);
    
    
    int cents = round(dollars * 100);
    int coins = 0;
    
    int denominations[] = {50, 25, 10, 5, 1};
    int size = sizeof (denominations)/sizeof(int);
    for (int i = 0; i < size; i++)
    {
        coins += cents / denominations[i];
        cents %= denominations[i];
    }
    printf("%i\n", coins);
}
1

You cannot directly assign a float value to an int First you need to treat float as an int and then you can assign it to int

int (name) = (int) (float_name);

I mean float contains decimal points which means that passing it to int won't work (I think so)

You can Google it for better understanding.

Anyways, why you don't put a counter inside a while loop to count the coins?

You must log in to answer this question.

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