Can't figure out error in my code when 4.2 is input as change will be then 420 but instead is coming out to be 419. What is wrong in my code?
#include<stdio.h>
#include<cs50.h>
int evaluate(int change){
int quarter,dime,nickel,penny;
int coins = 0;
quarter = change/25;
change = change%25;
printf("quarters:%d\n" ,quarter);
printf("change left: %d\n",change);
dime = change/10;
change = change%10;
printf("dimes:%d\n" ,dime);
printf("change left: %d\n",change);
nickel = change/5;
change = change%5;
printf("nickels:%d\n" ,nickel);
printf("change left: %d\n",change);
penny = change;
coins = quarter+dime+nickel+penny;
printf("pennies:%d\n" ,penny);
printf("change left: %d\n",change);
return coins;
}
int main()
{
printf("How much:");
float input = GetFloat();
int coin = 0;
while(true)
{
if(input>0)
{
int change = (100*input);
printf("change: %d\n",change);
coin = evaluate(change);
printf("%d\n",coin);
return 0;
}
else
{
printf("are you serious? retry:");
input = GetFloat();
} }
}
The program is to evaluate the least number of coins a cashier has to give to customer. Problem is that on getting input 4.2, the output is coming out wrong; also change=100*input
is coming out to be 419 for input to be 4.2. Please help me figure out problem.