Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <math.h>
  4. int main(void)
  5. {
  6.  
  7. float cash;
  8. int cents;
  9.  
  10.  
  11. int counter =0;
  12.  
  13.  
  14.  
  15. do{
  16.  
  17. printf("O hai! How much change is owed?\n");
  18. cash = get_float();
  19. }
  20. while (cash<0);
  21.  
  22. // take input the amount of cash owned
  23.  
  24. cents = cash * 100;
  25. cents = round(cash*100);
  26.  
  27. if (cents % 25 == 0)
  28. {
  29. counter += round(cents / 25);
  30. cents = 0;
  31.  
  32. }
  33. else if ( cents != 0 && cents % 25 != cents) {
  34. counter += round(cents / 25);
  35. cents = cents % 25;
  36.  
  37.  
  38. }
  39.  
  40.  
  41. if (cents != 0 && cents % 10 == 0)
  42. {
  43. counter += round(cents / 10);
  44.  
  45. cents = cents % 10;
  46.  
  47. }
  48. else if (cents != 0 && cents % 10 != cents)
  49. {
  50. counter += round(cents/10);
  51. cents = cents % 10;
  52.  
  53.  
  54. }
  55. //cents = 6
  56. if (cents != 0 && cents % 5 == 0)
  57. {
  58. counter += round(cents/5);
  59.  
  60. }
  61. else if ( cents != 0 && cents % 5 != cents)
  62. {
  63. counter += round(cents/5);
  64. cents = cents % 5;
  65.  
  66. }
  67.  
  68. else
  69. {
  70. //counter += cents;
  71.  
  72. }
  73. counter += cents;
  74. printf("%i\n", counter);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement