I'm having some trouble de-bugging my code for greedy.c of CS50 Pset1.
When I input 4.2, I get 12 instead of 18. When I input 0.2, I get 2 (the correct answer). When I input 4, I get 10 (so here is the problem).
I'm not sure how to solve this one! Any help is appreciated. Thanks!
Here is my code:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
//get change
int main(void)
{
float c;
int count = 0;
do
{
printf("How much change do you have to give back in $?\n");
c = get_float();
}
while (c < 0);
int change = round(c*100);
// get number of coins
while (change >= 25)
{
count++;
change -=25;
}
while (change >= 10)
{
count++;
change -=10;
}
while (change >= 5)
{
count++;
change -=5;
}
while (change >= 1)
{
count++;
change -=1;
}
printf("%x\n", count);
return 0;
}