I am trying to count the number of coins remained in order to give the client the least amount of coins.
But the last coin which is 0.01
always miscounts it.
I always get the number of coins -1
.
get_float()
is a special function to accept a float input.
#include <stdio.h>
#include <cs50.h>
int main(void) {
float coin;
int count;
do {
coin = get_float("enter the owed change?");
//printf("your cash %f", coin);
printf("\n");
} while (coin <= 0.00 || coin > 1.00);
//if (coin > 0.000000 && coin < 1.000000) {
count = 0;
while ((coin - 0.25) > 0) {
coin -= 0.25;
count++;
}
while ((coin - 0.10) > 0) {
coin -= 0.10;
count++;
}
while ((coin - 0.05) > 0) {
coin -= 0.05;
count++;
}
while ((coin - 0.01) > 0) {
coin -= 0.01;
count++;
}
if (coin == 0.01) {
count++;
}
//if (coin == 0.00) {
printf("%d", count);
//}
//}
}