0

I am trying to figure out why I am getting 3 errors when doing my check50...I think its got something to do with the pennies but can not figure it out for the life of me...please assist!!! I pasted the errors below along with a part of my code that might be calling the pennies wrong. Any assistance would be appreciated.

Errors:

:) greedy.c exists

:) greedy.c compiles

:( input of 0.41 yields output of 4

   \ expected output, but not "3\n"

:( input of 0.01 yields output of 1

   \ expected output, but not "0\n"

:) input of 0.15 yields output of 2

:) input of 1.6 yields output of 7

:) input of 23 yields output of 92

:( input of 4.2 yields output of 18

   \ expected output, but not "22\n"

:) rejects a negative input like -.1

:) rejects a non-numeric input of "foo"

:) rejects a non-numeric input of ""

Part of my code:

while (change >= quarter) 
{
    count++;
    change = change - quarter;
}

while (change >= dime) 
{
    count++;
    change = change - dime;
}

while (change >= nickel)
{
    count++;
    change = change - nickel;
}


while (change >= pennies)
{
    count++;
    change = change - pennies;
}

printf("%d\n", count);

}

1

Your code looks correct for counting the coins. I suspect that where you are having problems is actually converting the float to an integer. (Can't be completely certain since you didn't post that.) Double check that code to make sure you're getting what you expect. Use printf's or gdb as you wish. I had a problem there as well so you're not alone.

1

Your error is that on your second loop it should be in between a quarter and a dime value. In the third loop it should be in between a dime and a nickel value, etc.

It should be like this:

do
{
while(change < quarter && change > dime)
{
    //do this
}
while(change < dime && change > nickel)
{
    //do this
}
while(change < nickel && change > penny)
{
    //do this
}
while (change > 0.009);
2
  • Thank you for the response! I tried this but it still is not working.
    – user4891
    Jan 29 '15 at 11:52
  • Interesting... you set the values of the dimes and nickels and quarters, right? Also check above for update on code. Jan 30 '15 at 4:38

You must log in to answer this question.

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