I thought I had made the right code the behind my logic was to first divide the number with 25 and keeps on dividing it until the answer is less than one which means it cannot be divided any further and then proceed with the remaining amount to get it divided with 10 until it too cant b divided and in all of the process keep track of the counter for number of coins and the remaining amount of money left after each division. Two questions, is this logic right and if yes why am I getting the wrong answers and where are my mistakes?
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
float money;
int counter;
float input;
do
{
printf("How much money owed?\n ");
input = GetFloat();
}
while(input <= 0);
input = input * 100;
money = roundf (input);
//printf("%f", money);
counter = 0;
while (money / 25 >= 1)
{
money = money - money / 25;
counter++;
}
while (money / 10 >= 1)
{
money = money - money / 10;
counter++;
}
while (money / 5 >= 1)
{
money = money - money / 5;
counter++;
}
//final number of coins plus pennies
counter = counter + money;
printf ("%i \n", counter);
}