Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 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 = 0;
  8. do
  9. {
  10. dollars = get_float("How much do I owe you:");
  11. }
  12. while(dollars < 0);
  13.  
  14. int cents = round(dollars * 100);
  15.  
  16. int quarters = 0;
  17. if(cents >= 25)
  18. {
  19. quarters = cents / 25;
  20. }
  21.  
  22. int dimes = 0;
  23. if(( cents % 25 ) >= 10)
  24. {
  25. dimes = (cents % 25) / 10;
  26. }
  27.  
  28. int remainings = cents - (quarters * 25) - (dimes * 10);
  29. int nickels = 0;
  30. if((cents % 25) % 10 >= 5)
  31. {
  32. nickels = remainings / 5;
  33. }
  34.  
  35. int pennies = remainings % 5;
  36.  
  37. int total = quarters + dimes + nickels + pennies;
  38. {
  39. printf("%i\n", total);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement