Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.  
  8. float change, cents;
  9. int coins = 0;
  10.  
  11. // Prompt user for a float
  12. do
  13. {
  14. change = get_float("Please put in change: \n");
  15. }
  16. while (change <= 0);
  17.  
  18. // Changing dollars to cents
  19. cents = round (change * 100);
  20.  
  21. // Arithmetics
  22. {
  23.  
  24. while (cents >= 25)
  25. {
  26. cents -= 25;
  27. coins++;
  28. }
  29.  
  30. while (cents >= 10)
  31. {
  32. cents -= 10;
  33. coins++;
  34. }
  35.  
  36. while (cents >= 5)
  37. {
  38. cents -= 5;
  39. coins++;
  40.  
  41. while (cents >= 1)
  42. {
  43. cents -= 1;
  44. coins++;
  45. }
  46. }
  47.  
  48. //Output
  49. printf("Coins needed: %i", coins);
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement