Im new here my name is Brian Upward. Im having a bit of trouble with the greedy problem. This is returning outrageous numbers in the 30 thousands and I'm not sure why. I also tried a similar approach using a do/while loop and I received the same issues. I am sensing that the issue lies within the decimal but I'm not sure how else to write it. Any help would be greatly appreciated. Thanks, Brian
edit: Also I tried using (1/4) instead of 0.25 which didnt seem to work.
#include <cs50.h>
include
include
int main(void) { float change; int quarter, dime, nickel, penny;
printf("How much change is owed?\n");
change = GetFloat();
float roundf(float change);
while(change >= 0.25)
{
quarter = quarter + 1;
change = change - 0.25;
}
while(change >= 0.1)
{
dime = dime + 1;
change = change - 0.1;
}
while(change >= 0.05)
{
nickel = nickel + 1;
change = change - 0.05;
}
while(change >= 0.01)
{
penny = penny + 1;
change = change - 0.01;
}
printf("I owe you %i Quarters ", quarter);
printf("%i Dimes ", dime);
printf("%i Nickels ", nickel);
printf("and %i pennies. Thank you, have a nice day!", penny);
}