fork(1) download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #define TWENTY_BILL 20.00
  5. #define TEN_BILL 10.00
  6. #define FIVE_BILL 5.00
  7. #define ONE_BILL 1.00
  8. #define QUARTER_COIN 0.25
  9. #define DIME_COIN 0.10
  10. #define NICKEL_COIN 0.05
  11. #define PENNY_COIN 0.01
  12.  
  13. int main(int argc, char *argv[] ) {
  14.  
  15. /*
  16.  *Checks if argc has just one argument
  17.  *If not, give error message
  18.  */
  19. //if (argc < 2) {
  20. // printf("Error: One argument required.");
  21. // return 0;//If more than 1 argument, stops it
  22. //}//end if
  23.  
  24. double input;
  25. if (scanf("%lf\n", &input) != 1)
  26. return 1;
  27.  
  28. /*
  29.  * Converts argv[1] into double input
  30.  * Then input2 is created as a float
  31.  * input is transferred to input2
  32.  * Floor function is used, Multiplies
  33.  * input2 by 100 and then divide by 100 to
  34.  * leave only 2 decimal places
  35.  * Then Prints input2, %6.2f sets the field width
  36.  * for 2 decimal places
  37.  */
  38. //double input = atof(argv[1]);
  39. float input2;
  40. input2 = input;
  41. input2 = floor(input2 * 100) / 100;
  42. printf("You have entered: %6.2f\n", input2);
  43.  
  44. /*
  45.  * Creates variables for dollar
  46.  * bill and coin set to 0
  47.  */
  48. int twentycount = 0;
  49. int tencount = 0;
  50. int fivecount = 0;
  51. int onecount = 0;
  52. int quartercount = 0;
  53. int dimecount = 0;
  54. int nickelcount = 0;
  55. int pennycount = 0;
  56.  
  57. //Loops when input is greater than 0.0
  58. while (input2 > 0.0)
  59. {
  60. /*Twenty Dollar Bill
  61.   * When $20 is less than input2,
  62.   * input2 - $20 = new input2
  63.   * Add count to twentycount
  64.   */
  65. if (TWENTY_BILL <= input2)
  66. {
  67. input2 = input2 - TWENTY_BILL;
  68. twentycount++;
  69. }//end if twenty
  70. /************************/
  71. /*Ten Dollar Bill
  72.   * When $10 is less than input2,
  73.   * input2 - $10 = new input2
  74.   * Add count to tencount
  75.   */
  76. else if (TEN_BILL <= input2)
  77. {
  78. input2 = input2 - TEN_BILL;
  79. tencount++;
  80. }//end if ten
  81. /***********************/
  82. /*Five Dollar Bill
  83.   * When $5 is less than input2,
  84.   * input2 - $5 = new input2
  85.   * Add count to fivecount
  86.   */
  87. else if (FIVE_BILL <= input2)
  88. {
  89. input2 = input2 - FIVE_BILL;
  90. fivecount++;
  91. }//end if five
  92. /**********************/
  93. /*One Dollar Bill
  94.   * When $1 is less than input2,
  95.   * input2 - $1 = new input2
  96.   * Add count to onecount
  97.   */
  98. else if (ONE_BILL <= input2)
  99. {
  100. input2 = input2 - ONE_BILL;
  101. onecount++;
  102. }//end if one
  103. /*********************/
  104. /*Quarter Coin
  105.   * When $0.25 is less than input2,
  106.   * input2 - $0.25 = new input2
  107.   * Add count to quartercount
  108.   */
  109. else if (QUARTER_COIN <= input2)
  110. {
  111. input2 = input2 - QUARTER_COIN;
  112. quartercount++;
  113. }//end if quarter
  114. /*********************/
  115. /*Dime Coin
  116.   * When $0.10 is less than input2,
  117.   * input2 - $0.10 = new input2
  118.   * Add count to dimecount
  119.   */
  120. else if (DIME_COIN <= input2)
  121. {
  122. input2 = input2 - DIME_COIN;
  123. dimecount++;
  124. }//end if dime
  125. /*********************/
  126. /*Nickel Coin
  127.   * When $0.05 is less than input2,
  128.   * input2 - $0.05 = new input2
  129.   * Add count to nickelcount
  130.   */
  131. else if (NICKEL_COIN <= input2)
  132. {
  133. input2 = input2 - NICKEL_COIN;
  134. nickelcount++;
  135. }//end if nickel
  136. /*********************/
  137. /*Penny Coin
  138.   * When $0.01 is less than input2,
  139.   * input2 - $0.01 = new input2
  140.   * Add count to pennycount
  141.   */
  142. else if (PENNY_COIN <= input2)
  143. {
  144. input2 = input2 - PENNY_COIN;
  145. pennycount++;
  146. }//end if penny
  147. /********************/
  148. /*
  149.   * If anything else
  150.   * Print Invalid Change
  151.   */
  152. else
  153. {
  154. printf("Invalid change");
  155. }
  156.  
  157. }//end while loop
  158.  
  159. /*
  160.   * If twentycount is more than 0
  161.   * Print amount of $20 bills used
  162.   */
  163. if (twentycount > 0)
  164. {
  165. printf("Amount of $20: %i\n", twentycount);
  166. }//end twentycount
  167. /*
  168.   * If tencount is more than 0
  169.   * Print amount of $10 bills used
  170.   */
  171. if (tencount > 0)
  172. {
  173. printf("Amount of $10: %i\n", tencount);
  174. }//end tencount
  175. /*
  176.   * If fivecount is more than 0
  177.   * Print amount of $5 bills used
  178.   */
  179. if (fivecount > 0)
  180. {
  181. printf("Amount of $5: %i\n", fivecount);
  182. }//end fivecount
  183. /*
  184.   * If onecount is more than 0
  185.   * Print amount of $1 bills used
  186.   */
  187. if (onecount > 0)
  188. {
  189. printf("Amount of $1: %i\n", onecount);
  190. }//end onecount
  191. /*
  192.   * If quartercount is more than 0
  193.   * Print amount of $0.25 bills used
  194.   */
  195. if (quartercount > 0)
  196. {
  197. printf("Amount of $0.25: %i\n", quartercount);
  198. }//end quartercount
  199. /*
  200.   * If dimecount is more than 0
  201.   * Print amount of $0.10 bills used
  202.   */
  203. if (dimecount > 0)
  204. {
  205. printf("Amount of $0.10: %i\n", dimecount);
  206. }//end dimecount
  207. /*
  208.   * If nickelcount is more than 0
  209.   * Print amount of $0.05 bills used
  210.   */
  211. if (nickelcount > 0)
  212. {
  213. printf("Amount of $0.05: %i\n", nickelcount);
  214. }//end nickelcount
  215. /*
  216.   * If pennycount is more than 0
  217.   * Print amount of $0.01 bills used
  218.   */
  219. if (pennycount > 0)
  220. {
  221. printf("Amount of $0.01: %i\n", pennycount);
  222. }//end pennycount
  223.  
  224.  
  225. return 0;
  226. }//end main
Success #stdin #stdout 0s 2900KB
stdin
65.25
stdout
You have entered:  65.25
Amount of $20: 3
Amount of $5: 1
Amount of $0.25: 1