I tried to use for loops to solve the cash (less) problem set, not sure if thats possible. Can this code be fixed or do I need to use while loops instead? the code compiles, but the output is either (input)*100+2, or it gets stuck in an infinite loop.
# include <stdio.h>
# include <cs50.h>
# include <math.h>
int main (void) {
//ask for change
float c;
int i = 0;
do
{
c = get_float("Change owed: \n");
}
while (c < 0.00);
int d = round(c * 100);
//check how many quarters can be used
for ( ; d > 25 ; d = d - 25, i++)
//check how many dimes can be used
for ( ; d > 10 ; d = d - 10, i++)
//check how many nickles can be used
for ( ; d > 5 ; d = d - 5, i++)
//check how many pennies can be used
for ( ; d > 1 ; d = d - 1, i++);
//display total ammount of coins used
if (d <= 0) {
printf("%i\n", i);
}
}