Advertisement
vires1

Untitled

Jan 17th, 2014
164
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 counter;
  10.  
  11. //a loop to take the user input
  12. do
  13. {
  14. printf("how much change is owed? ");
  15. dollars = GetFloat();
  16.  
  17. }
  18.  
  19.  
  20. while (dollars <= 0 );
  21.  
  22. int cent = round(dollars * 100);
  23.  
  24.  
  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. while(dimes >= 10)
  33. {
  34. counter++;
  35. cent = cent - 10;
  36. }
  37. while (nickel >= 5)
  38. {
  39. counter++;
  40. cent = cent - 5;
  41. }
  42. while (penny >= 1)
  43. {
  44. counter++;
  45. cent = cent - 1;
  46. }
  47. printf("i have %d coins\n",counter);
  48.  
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement