0

My current code checks out all the input values except for the integer value of 23. I'm not sure why, and the value is pretty close, 94, instead of 92. But what makes me truly confused is that other answers have a similar or exact code than mine, but the output is different!

:) cash exists

:) cash compiles

:) input of 0.41 yields output of 4

:) input of 0.01 yields output of 1

:) 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

:) rejects a negative input like -1

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

:) rejects a non-numeric input of ""

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

int main(void)
{
    int count = 0; // counts how many cents we are using
    float dollars;
    int cents;
    do{
        dollars = get_float("Change owed: ");
    }
    while (dollars < 0.00);
    printf("Stored: %f\n", dollars);
    cents = round(dollars * 100);
    printf("%i\n",cents);
    while (cents - 25 > 0)
    {
        cents = cents - 25;
        count++;
    }
    while (cents - 10 >= 0)
    {
        cents = cents - 10;
        count++;
    }
    while (cents - 5 >= 0)
    {
        cents = cents - 5;
        count++;
    }
    while (cents - 1 >= 0)
    {
        cents = cents - 1;
        count++;
    }
    printf("%i", count);
}
0

Found it.

while (cents - 25 >= 0)

and not

while (cents - 25 > 0)

You must log in to answer this question.

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