Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<cs50.h>
  3. #include<math.h>
  4.  
  5. int main(void)
  6. {
  7. {
  8. float x;
  9. //Prompt user for change owed
  10. {
  11. do
  12. {
  13. x = get_float("Change owed:");
  14. }
  15. while (x < 0);
  16.  
  17. }
  18.  
  19. int coins;
  20. // to store change owed
  21. int n ;
  22.  
  23. //Convert float to integer
  24. n = round(x * 100);
  25.  
  26. //Count the number of coins
  27. coins = 0;
  28.  
  29. //Number of Quarters
  30. while (n >= 25)
  31. {
  32. coins += 1;
  33. n = n - 25;
  34. }
  35.  
  36. //Number of Dimes
  37. while (n >= 10)
  38. {
  39. coins += 1;
  40. n = n - 10;
  41. }
  42.  
  43. //Number of Nickels
  44. while (n >= 5)
  45. {
  46. coins += 1;
  47. n = n - 5;
  48. }
  49.  
  50. //Number of Pennies
  51. while (n >= 1)
  52. {
  53. coins += 1;
  54. n = n - 5;
  55. }
  56.  
  57. // Display number of coins
  58.  
  59. printf("%d\n", coins);
  60.  
  61.  
  62. }
  63. }
Add Comment
Please, Sign In to add comment