After tinkering with the syntax and perusing the over blog related to floating number imprecision I thought I had cracked the nut with my attempt to round my numbers. But when I enter 0.41 in my terminal I get a runtime error instead of the the 4 coins it should take to get to 41p.
Is my syntax/formula correct for rounding floats correct?
//Prompt user for an amount of change
do
{
dollars = get_float("change owed: ");
}
while (dollars < 0);
//convert float (dollars) to integer (cents) and then round
int cents = round(dollars * 100);
int coins = 0;
while (cents >= 25)
{
coins++;
cents-= 25;
}
while (cents >= 10)
{
coins++;
cents -=10;
}
while (cents >= 5)
{
coins++;
cents +=5;
}
while (cents >= 1)
{
coins++;
cents -=1;
}
printf("%i\n", coins);
}
i am getting this error message - runtime error: signed integer overflow: 2147483646 + 5 cannot be represented in type 'int' 429496731