Guest User

Untitled

a guest
Jan 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <cs50.h>
  4.  
  5. int main(void)
  6. {
  7. int coinsReturned = 0;
  8.  
  9. printf("How much change is owed? \n");
  10. float change = get_float();
  11.  
  12. while (change < 0) {
  13. printf("How much change is owed? \n");
  14. change = get_float();
  15. }
  16.  
  17.  
  18. int amount = round(change * 100);
  19.  
  20. while (amount > 0) {
  21. if ((amount - 25) >= 0) { amount = amount - 25; coinsReturned++; }
  22. else if ((amount - 10) >= 0) { amount = amount - 10; coinsReturned++; }
  23. else if ((amount - 5) >= 0) { amount = amount - 5; coinsReturned++; }
  24. else if ((amount - 1) >= 0) { amount = amount - 1; coinsReturned++; }
  25. }
  26.  
  27. printf("%d coins\n", coinsReturned);
  28. }
Add Comment
Please, Sign In to add comment