Advertisement
pmg2020

Untitled

May 4th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int main(void)
  6. {
  7. float dollars;
  8. int q = 0,d = 0,n = 0,p = 0;
  9.     do
  10.     {
  11.         dollars = get_float("How much change is owed to you?");
  12.     }
  13.     while (dollars < 0);
  14.  
  15.     int cents = round(dollars * 100);
  16.  
  17.     printf("you entered: %d\n", cents);
  18.    
  19.    
  20.     while(cents-25>=0)
  21.     {
  22.         q=q+1;
  23.         cents=cents-25
  24.     }
  25.     while(cents-10>=0)
  26.     {
  27.         d=d+1;
  28.         cents=cents-10
  29.     }
  30.     while(cents-5>=0)
  31.     {
  32.         n=n+1;
  33.         cents=cents-5
  34.     }
  35.     while(cents-1>=0)
  36.     {
  37.         p=p+1;
  38.         cents=cents-1
  39.     }
  40.     printf("25 cents coins = %d /n 10 cents coins = %d /n 5 cents coins = %d /n 1 cent coins = %d /n",q,d,n,p);
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement