nicolaasvdw

PSet 1 Cash

May 19th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4.  
  5. int get_amount(void);
  6.  
  7. int main(void)
  8. {
  9.    // Get user input for Change Owed
  10.    float a = get_amount();
  11.    
  12.    // Convert to cents
  13.     int cents = round(a * 100);
  14.    
  15.     // Set coin counter to 0
  16.     int counter = 0;
  17.    
  18.     while (cents >= 25)
  19.     {
  20.         cents -= 25;
  21.         counter++;
  22.     }    
  23.  
  24.     while (cents >= 10)
  25.     {
  26.         cents -= 10;
  27.         counter++;
  28.     }
  29.  
  30.     while (cents >= 5)
  31.     {
  32.         cents -= 5;
  33.         counter++;
  34.     }
  35.  
  36.     while (cents >= 1)
  37.     {
  38.         cents --;
  39.         counter++;
  40.     }
  41.    
  42.     printf("%i\n", counter);
  43. }
  44.  
  45.  
  46. // Function: User input for Change Owed
  47. int get_amount(void)
  48. {
  49.     float amount;
  50.     do
  51.     {
  52.         amount = get_float("Changed owed: ");
  53.     }
  54.         while (amount < 0);
  55.         return amount;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment