I'm creating a greedy loop that finds the smallest amount of coins to be used to give back a value for CS50's pset1, and I can't decipher why my while loop is running infinitely.
I've tinkered with it and can't get it to escape.
#include <stdio.h>
#include <cs50.h>
#include <math.h>
// declare variable change_owed, num_coins, and input globally
float change_owed;
float input;
int num_coins;
int main(void)
{
// makes sure the input is non-negative
do
{
input = get_float("Amount paid\n");
}
while(change_owed <=0);
input = round(input);
// begin checking
while(input > 0)
{
if(input - .25 > 0) // quarters
{
num_coins++; // number of coins used, to be printed later, is incremented
input = input - .25; // coin is subtracted from total
}
else if (input - .10 > 0) // dimes
{
num_coins++;
input = input - .10;
}
else if (input - .05 > 0) // nickels
{
num_coins++;
input = input - .05;
}
else if (input - .01 > 0) // pennies
{
num_coins++;
input = input - .01;
}
}
printf("%i", num_coins);
}