# cs50 pset1 cash -greedy challenge

This is a problem in cs50 which states

Implement a program that calculates the minimum number of coins required to give a user change.

The output of the problem is the number of coins to be given to the user.I made the program and it is working almost perfectly but for 4.2 dollars the output is 22 but it should have been 18. Every other value the ouput is correct. Can anyone tell what is wrong with this code?

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

int main(void)
{
float change_owed, change_owed_in_hundreds;
int number_of_coins_to_be_given = 0;
do
{
printf("enter the positve ammount of change owed in dollars");
change_owed = get_float();
}while(c < 0);

change_owed_in_hundreds = change_owed * 100;

while(change_owed_in_hundreds >= 25){
change_owed_in_hundreds = change_owed_in_hundreds - 25;
number_of_coins_to_be_given++;
}
while(change_owed_in_hundreds >= 10) {
change_owed_in_hundreds = change_owed_in_hundreds - 10;
number_of_coins_to_be_given++;
}
while(change_owed_in_hundreds >= 5) {
change_owed_in_hundreds = change_owed_in_hundreds - 5;
number_of_coins_to_be_given++;
}
while(change_owed_in_hundreds >= 1) {
change_owed_in_hundreds = change_owed_in_hundreds - 1;
number_of_coins_to_be_given++;
}

printf("%d\n", number_of_coins_to_be_given);
}
``````