Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3.  
  4. int main (void)
  5. {
  6. float dollars = 0;
  7.  
  8.  
  9. // get input, if not valid; retry
  10. do
  11. {
  12. printf("Amount of change (in $): ");
  13. dollars = GetFloat();
  14.  
  15. if (dollars <= 0)
  16. {
  17. printf("Must be positive, try again.\n");
  18. }
  19. } while (dollars <= 0);
  20.  
  21. // turn dollars into cents, make quarters, dime etc. into integers
  22. int cents = (int) (dollars * 100);
  23. double round(double cents);
  24. int q = 25;
  25. int d = 10;
  26. int n = 5;
  27. int p = 1;
  28.  
  29. //variable for counting number of coins for change
  30. int coins = 0;
  31.  
  32. // if cents bigger than 25 then subtract 25 and so forth
  33. if (cents > q)
  34. {
  35. cents = (cents - q);
  36. coins++;
  37. }
  38.  
  39. else if (cents > d)
  40. {
  41. cents = (cents - d);
  42. coins++;
  43. }
  44.  
  45. else if (cents > n)
  46. {
  47. cents = (cents - n);
  48. coins++;
  49. }
  50.  
  51. else
  52. {
  53. cents = (cents - p);
  54. coins++;
  55. printf("Amount of coins back: %i\n", coins);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement