The following code converts dollars (floating values) into cents (integer values). Here 1 dollar == 100 cents. The code works flawlessly except for one value i.e 4.2. It gives output as 419 instead of 420 for 4.2 as input. Where is the bug?
#include <stdio.h>
int main(void)
{
float change;
do
{
printf("O hai! Enter amount in dollars to convert in cents.\n");
scanf("%f",&change); //accepts input in dollars
} while(change < 0.00);
int i = change * 100; //converts dollars into cents
printf("The equivalent cents are %d\n",i);
}