Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <math.h>
- int main(void)
- {
- float f;
- int cents;
- int reminder;
- int coins;
- do
- {
- f = get_float("Change: ");
- }
- while (f <= 0);
- cents = round(f * 100);
- do
- {
- if (cents % 25 >= 0)
- {
- reminder = cents % 25;
- cents = (cents/25);
- coins = floor(cents);
- }
- else if ((cents % 10 >= 0) || (reminder % 10 >= 0))
- {
- reminder = cents % 10;
- cents = (cents/10);
- coins = floor(cents);
- }
- else if ((cents % 5 >= 0) || (reminder % 5 >= 0))
- {
- reminder = cents % 5;
- cents = (cents/5);
- coins = floor(cents);
- }
- else
- {
- cents = reminder + cents + coins;
- }
- }
- while (cents > 0 || reminder > 0 || coins > 0);
- printf("Amount of coins: %i\n", cents);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement