I've been trying to make the greedy problem set, but something isn't working. The program works fine with numbers like 1,2,3,4... But it fails when I try to use a decimal number. This is my code:
enter code here#include
<cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
// Variables to store counting data
float coin_count = 0;
float owed;
// Prompts user for a valid float
do
{
printf("O hai! How much change is owed?\n");
owed = roundf(GetFloat());
}
while (owed <= 0);
// Checks what which coins to use
for (float quarter = .25; owed >= quarter; coin_count++)
{
owed = owed - quarter;
}
for (float dime = .10; owed >= dime; coin_count++)
{
owed = owed - dime;
}
for (float nickel = .05; owed >= nickel; coin_count++)
{
owed = owed - nickel;
}
for (float penny = .01; owed >= penny; coin_count++)
{
owed = owed - penny;
}
//coin_count = round(coin_count);
printf("%.50f\n", coin_count);
}
I tried multiplying and dividing by 100 but that didn't work for me :/ Could someone help me?