I am new to this forum and to programming for that matter.
I am following the CS50 (computer science) online course
from last year and I have problems with one of the assignments.
I am supposed to write a code to calculate the amount of coins
it takes to give change from certain amount of dollars inputed.
There are only 4 coins used (quarter, dime, nickel and penny).
I have found some other similar programs online but I would really
like to know what's wrong with my code.
And I can't believe that somebody asked identical question a few
minutes before me.
Thanks for any help
int main (void)
// asks user to enter the amount and veryfies the input
printf("Enter the amount to get change for:");
while (dollars <= 0);
// converts dollars into cents
int cents = round(dollars * 100);
// calculates the number of coins needed to give change
int quarter = 25;
int dime = 10;
int nickel = 5;
int penny = 1;
int coins = 0;
while (cents >= quarter)
cents -= quarter;
while (cents >= dime)
cents -= dime;
while (cents -= nickel)
cents -= nickel;
while (cents -= penny)
cents -= penny;