Math is wrong but still an accurate output???
I'm trying to follow the math of this example program but as you can see in the comments I've been trying to work out the math, but when I follow the given equations it doesn't calculate correctly, yet the program still gives an accurate output...what am I missing? How is the change function working?
Code:
#include <stdio.h>
#include<stdio.h>
void change(float coin)
{
float abc = coin*10.0*10.0; /*12.59 * 10.0 * 10.0=1259*/
int sum = abc;
int x, y, z;
z = sum / 25; /* 1259/25= 50.36 */
printf(" %d quarters \n", z);
sum = sum - z * 25; /*1259-50.36*25*/
y = sum / 10;
printf(" %d dime \n", y);
sum = sum - y * 10;
x = sum / 5;
printf(" %d nickels \n", x);
sum = sum - x * 5;
printf(" %d pennies \n", sum);
}
int main()
{
float d;
printf(" Enter a value for change :");/*EXAMPLE TEST WITH $12.59*/
scanf_s("%f", &d);
change(d);
getchar();
getchar();
return 0;
}