0

So I'm having issues with this producing the right answer for a some money values like .53. It gives me 4 coins when it should be 5.

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    int counter = 0;
    float money;

    do
    {
        printf("Enter the value of your money:");
        money = (int) (100* get_float());
    }
    while (money < 0);

    while (money >= 25)
    {
        money = (money - 25);
        counter++;
    }

    while (money >= 10)
    {
        money = (money - 10);
        counter++;
    }

    while (money >= 5)
    {
        money = (money - 5);
        counter++;
    }

    while (money >= 1)
    {
        money = (money - 1);
        counter++;
    }

    printf("%i\n", counter);
}

1 Answer 1

1

You have to round off your money after storing and multiplying with 100. See the walkthroughs carefully. Add following line to your code after the first do - while loop. this round function comes with math.h header file, so don't forget to add that.

 #include <math.h>
  money = round(money);
1
  • Thank! I just missed that part completely the first time I watched.
    – TreeDoan
    Commented Jul 31, 2017 at 20:53

You must log in to answer this question.

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