Guest User

Untitled

a guest
Jan 16th, 2014
38
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. while (dollars <= 0 );
  24. //changing from float to int.
  25. int cent = round(dollars * 100);
  26.  
  27.  
  28. //loops to collect input and give number of coins left.
  29. while (dollars >= 25)
  30. counter ++;
  31. quarters --;
  32. dollars = dollars / 5;
  33. dollars = dollars % 25;
  34. while (dollars >= 10)
  35. counter++;
  36. dimes--;
  37. dollars = dollars % 10;
  38. while (dollars >= 5)
  39. counter++;
  40. nickel--;
  41. dollars = dollars / 5;
  42. dollars = dollars % 5;
  43. while (dollars >= 1)
  44. counter++;
  45. penny --;
  46. dollars = dollars / 1;
  47. dollars = dollars % 1;
  48.  
  49. printf("i have %d coins ", counter);
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment