0

I have written the following code for cash pset1

#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
float dollars;
do
{
   dollars = get_float("Enter The Money Owed = ");
}
while ( dollars < 0 );
int cents = round(dollars*100);

int quarters = 0;
while (quarters <= cents/25)
{
   quarters++;
}

int dimes=0;
while (dimes <= (cents-25*quarters)/10)
 {
   dimes++;
}

int nickels=0;
while (nickels <= (cents-25*quarters-10*dimes)/5)
 {
   nickels++;
}

int pennies=0;
while (pennies <= (cents-25*quarters-10*dimes-5*nickels))
 {
   pennies++;
}
printf("%d \n", quarters + dimes + nickels + pennies);
}

I found the error which is supposedly due to using <= instead of simply < however when i tried working out the case of 0.15 which give 2 as the correct answer using my original method (the one in code above) I was getting the answer 2 but the program showed the answer 1. What mistake am I making?

You must log in to answer this question.

Browse other questions tagged .