Advertisement
Guest User

help50

a guest
Feb 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4.  
  5. int main(void)
  6. {  
  7. float f;
  8. int cents;
  9. int reminder;
  10. int coins;
  11.     do
  12.     {
  13.         f = get_float("Change: ");
  14.     }
  15.     while (f <= 0);
  16.     cents = round(f * 100);
  17.     do
  18.     {
  19.         if  (cents % 25 >= 0)
  20.         {
  21.             reminder = cents % 25;
  22.             cents = (cents/25);
  23.             coins = floor(cents);
  24.         }
  25.         else if ((cents % 10 >= 0) || (reminder % 10 >= 0))
  26.         {
  27.             reminder = cents % 10;
  28.             cents = (cents/10);
  29.             coins = floor(cents);
  30.         }
  31.         else if ((cents % 5 >= 0) || (reminder % 5 >= 0))
  32.         {
  33.             reminder = cents % 5;
  34.             cents = (cents/5);
  35.             coins = floor(cents);
  36.         }
  37.         else
  38.         {
  39.             cents = reminder + cents + coins;
  40.         }
  41.     }
  42.     while (cents > 0 || reminder > 0 || coins > 0);
  43.     printf("Amount of coins: %i\n", cents);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement