Advertisement
Guest User

Untitled

a guest
Jan 17th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cs50.h>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. int main (void)
  6. {
  7.  
  8. float dollars;
  9.  
  10. int counter = 0;
  11.  
  12. //a loop to take the user input
  13. do
  14. {
  15. printf("how much change is owed? ");
  16. dollars = GetFloat();
  17.  
  18. }
  19.  
  20.  
  21. while (dollars <= 0 );
  22.  
  23. //changing from float to int
  24. int cent = round(dollars * 100);
  25.  
  26. //loops to collect input and give number of coins left.
  27. while (cent >= 25)
  28. {
  29. counter ++;
  30. cent = cent - 25;
  31.  
  32. }
  33. while(cent > 10)
  34. {
  35. counter++;
  36. cent = 10 - cent;
  37. }
  38. while (cent > 5)
  39. {
  40. counter++;
  41. cent = 5 - cent;
  42.  
  43. }
  44. while (cent > 1)
  45. {
  46.  
  47. counter++;
  48. cent = 1 - cent;
  49. }
  50. printf("%d\n",counter);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement