Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <cs50.h>
  4.  
  5. int main(void)
  6. {
  7.     float change;
  8.     float remains;
  9.     float quarter = 0.25;
  10.     float dime = 0.10;
  11.     float nickel = 0.05;
  12.     float penny = 0.01;
  13.     int numberOfCoins = 0;
  14.    
  15.     do
  16.     {
  17.         printf("How much change is owed?: ");
  18.         change = get_float();
  19.     }
  20.     while(change <= 0);
  21.    
  22.     remains = change;
  23.     while(remains >= quarter)
  24.     {
  25.         remains = remains - quarter;
  26.         numberOfCoins++;
  27.     }
  28.    
  29.     while(remains >= dime)
  30.     {
  31.         remains = remains - dime;
  32.         numberOfCoins++;
  33.     }
  34.    
  35.     while(remains >= nickel)
  36.     {
  37.         remains = remains - nickel;
  38.         numberOfCoins++;
  39.     }
  40.    
  41.     while(remains >= penny)
  42.     {
  43.         remains = remains - penny;
  44.         numberOfCoins++;
  45.     }
  46.  
  47.     printf("%d\n", numberOfCoins);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement