Advertisement
vires1

Untitled

Jan 17th, 2014
225
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. int quarters = 0;
  10. int dimes = 0;
  11. int penny = 0;
  12. int nickel = 0;
  13. int counter = 0;
  14.  
  15. //a loop to take the user input
  16. do
  17. {
  18. printf("how much change is owed? ");
  19. dollars = GetFloat();
  20.  
  21. }
  22.  
  23.  
  24. while (dollars <= 0 );
  25.  
  26. int cent = round(dollars * 100);
  27.  
  28.  
  29.  
  30. //loops to collect input and give number of coins left.
  31. while (quarters >= 25)
  32. {
  33. counter++;
  34. quarters = cent - 25;
  35.  
  36.  
  37.  
  38. while(dimes >= 10)
  39. counter++;
  40. dimes = cent - 10;
  41.  
  42.  
  43. while (nickel >= 5)
  44. counter++;
  45. nickel = cent - 5;
  46.  
  47.  
  48.  
  49. //dollars = cent / 5;
  50. nickel = cent % 5;
  51. while (penny >= 1)
  52. counter++;
  53. penny = cent - 1;
  54.  
  55.  
  56. printf("i have %d coins\n",counter);
  57. break;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement