0

I recently finished my greedy program and checked it out using different values and it appears to work except for large numbers (more than 6 digits) because of the float problem.

So, I checked it with check50 by executing

check50 2014/x/pset1/greedy greedy.c

I got several errors. For example, it said that my program output 7 for the value 1.6.

However, when I tried it, 1.6 gave me 3, which is correct.

Even stranger, I tried the program they wrote by executing

~cs50/pset1/greedy

And the answers were all incorrect.

I think I understand the pset specifications, so what am I doing wrong?

3

The correct answer for 1.6 is 7.

1.6 is $1.60 which is 160 cents. Given the available coins of 25c, 10c, 5c, and 1c, the smallest number is 6 quarters (150 cents) and 1 dime (10 cents) to equal 160 cents.

Looks like you are ignoring the dollars? You need to include them.

Brenda.

3
  • 1
    Oh, I see! Thanks, I was able to change my program and in fact make it a bit easier since there was one less calculation. I guess for some reason my mind automatically assumed that getting the number of coins back meant that anything over a dollar was dismissed since it would be a bill (unless you're talking about Canadian money). I can't believe I spent such a long time trying to figure out why my program 'wasn't working' when it gave the exact answer I wanted.
    – Jonobugs
    Jun 12 '14 at 1:02
  • Glad to help. You might want to mark my answer as accepted so this will show as answered. -Brenda.
    – curiouskiwi
    Jun 12 '14 at 21:02
  • @Jonobugs I also thought we were dealing only with the cents portion. Returning 45.75 with a bunch of quarters seems odd.
    – m_duran
    Jul 6 '14 at 4:16

You must log in to answer this question.

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