Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<cs50.h>
  3.  
  4. int penny(int n, int temp)
  5. {
  6.  
  7.  
  8. if(n>=25){
  9. n -= 25;
  10. temp++;
  11. }
  12. else if(n>=10 && n<25){
  13. n -= 10;
  14. temp++;
  15. }
  16. else if(n>=5 && n<10){
  17. n -= 5;
  18. temp++;
  19. }
  20. else if(n>=1 && n<10){
  21. n -= 1;
  22. temp++;
  23. }
  24.  
  25. if(n>0)
  26. {
  27. //printf("n=%d/n",n);
  28. //printf("temp=%d/n",temp);
  29. return(penny(n, temp));
  30. }
  31.  
  32. return temp;
  33.  
  34. }
  35.  
  36. int main(void)
  37. {
  38. float change;
  39. int n, count=0;
  40.  
  41. do{
  42. printf("O hai! How much change is owed?\n");
  43. change = get_float();
  44. }while(change<0);
  45.  
  46. n = (int)(change*100)%100;
  47. count = penny(n, count);
  48. printf("%d\n",count);
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement