Desperately need help for pset 1 cash!
My code failed 2 of the check50 tests: :( input of 23 yields output of 92 :( input of 4.2 yields output of 18
I believe it's a rounding problem, but I've been trying and retrying and searching but I still can't find a solution.
#include <stdio.h>
#include <math.h>
#include <cs50.h>
int main(void)
{
float c;
int t, n=0;
do
{
c = get_float("Change owed: ");
}
while (c < 0);
//Round and convert
c *=100;
t =round(c);
//quarters
while (t >= 25)
{
n++;
t -=25;
}
//dimes
while (t >= 10)
{
n++;
t -=10;
}
//nickels
while (t >= 5)
{
n++;
t -=5;
}
//pennies
while (t>=1)
{
n++;
t -=1;
}
//prints coins used
printf("%o\n", n);
}