daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  NAME: James Toste
  2.     PURPOSE: The program takes in the number of volumes and price per stated volumes for three          book collections, as well as the budget of the buyer. It then prints various            information about the situation.
  3.     DATE: 9/20/2017     */
  4.  
  5.  
  6. #include <stdio.h>
  7.  
  8.     int main(void)
  9.     {
  10.  
  11. int col1n, col1p, col2n, col2p, col3n, col3p, bobbdgt, col1tp, col2tp, col3tp, col123tp, i, p, k, j;
  12. //---#n means number, ---#p means price, ---#tp means total price//
  13.  
  14. printf("Enter volumes and price per volume for collection 1: ");
  15. scanf("%d %d", &col1n, &col1p);
  16.  
  17. printf("Enter volumes and price per volume for collection 2: ");
  18. scanf("%d %d", &col2n, &col2p);
  19.  
  20. printf("Enter volumes and price per volume for collection 3: ");
  21. scanf("%d %d", &col3n, &col3p);
  22.  
  23. printf("Enter Bob's budget: ");
  24. scanf("%d", &bobbdgt);
  25.  
  26. if (bobbdgt > 0)
  27. {
  28.     printf("(1) Bob has some money to buy collections.\n");
  29. }
  30. else
  31. {
  32.     printf("(1) Bob does not have money to buy anything.\n");
  33. }
  34.  
  35. col1tp = col1n * col1p;
  36. col2tp = col2n * col2p;
  37. col3tp = col3n * col3p;
  38. col123tp = col1tp + col2tp + col3tp;
  39.  
  40. if (bobbdgt >= col123tp)
  41. {
  42.     printf("(2) Bob has enough money to buy all three collections.\n");
  43. }
  44. else
  45. {
  46.     printf("(2) Bob does not have enough money to buy all three collections.\n");
  47. }
  48.  
  49. /*##########################################
  50.   Here begins the if/else statements for (3)
  51.   ########################################## */
  52.  
  53. i = 0;
  54.  
  55. if (bobbdgt <= col1tp)
  56. {
  57.      i += 1;
  58. }
  59. else
  60. {
  61.     i += 0;
  62. }
  63.  
  64. if (bobbdgt <= col2tp)
  65. {
  66.     i += 1;
  67. }
  68. else
  69. {
  70.     i += 0;
  71. }
  72.  
  73. if (bobbdgt <= col3tp)
  74. {
  75.     i += 1;
  76. }
  77. else
  78. {
  79.     i += 0;
  80. }
  81.  
  82. if (i >= 2)
  83. {
  84.     printf("(3) At least two collections are more expensive than Bob's budget.\n");
  85. }
  86. else
  87. {
  88.     printf("(3) At least two collections are cheaper than or equal to Bob's budget.\n");
  89. }
  90.  
  91. /*##########################################
  92.   Here begins the if/else statements for (4)
  93.   ########################################## */
  94.  
  95. p = 0;
  96.  
  97. if (col1tp == col2tp)
  98. {
  99.     p += 1;
  100. }
  101. else
  102. {
  103.     p += 0;
  104. }
  105.  
  106. if (col1tp == col3tp)
  107. {
  108.     p += 1;
  109. }
  110. else
  111. {
  112.     p += 0;
  113. }
  114.  
  115. if (col2tp == col3tp)
  116. {
  117.     p += 1;
  118. }
  119. else
  120. {
  121.     p += 0;
  122. }
  123.  
  124. if (p >= 1)
  125. {
  126.     printf("(4) At least two collections cost the same amount of money.\n");
  127. }
  128. else
  129. {
  130.     printf("(4) No two collections have the same price.\n");
  131. }
  132.  
  133. /*##########################################
  134.   Here begins the if/else statements for (5)
  135.   ########################################## */
  136.  
  137. k = 0;
  138.  
  139. if (col1tp <= bobbdgt)
  140. {
  141.     k += 1;
  142. }
  143. else
  144. {
  145.     k += 0;
  146. }
  147.  
  148. if (col2tp <= bobbdgt)
  149. {
  150.     k += 1;
  151. }
  152. else
  153. {
  154.     k += 0;
  155. }
  156.  
  157. if (col3tp <= bobbdgt)
  158. {
  159.     k += 1;
  160. }
  161. else
  162. {
  163.     k += 0;
  164. }
  165.  
  166. if (k == 1)
  167. {
  168.     printf("(5) Only one collection is cheaper than or equal to Bob's budget.\n");
  169. }
  170. else
  171. {
  172.     printf("(5) More than one collection is cheaper than or equal to Bob’s budget or they are all more expensive.\n");
  173. }
  174.  
  175. /*##########################################
  176.   Here begins the if/else statements for (6)
  177.   ########################################## */
  178.  
  179. j = 0;
  180.  
  181. if (bobbdgt >= col1tp)
  182. {
  183.     j += 1;
  184. }
  185. else
  186. {
  187.     j += 0;
  188. }
  189.  
  190. if (bobbdgt >= col2tp)
  191. {
  192.     j += 1;
  193. }
  194. else
  195. {
  196.     j += 0;
  197. }
  198.  
  199. if (bobbdgt >= col3tp)
  200. {
  201.     j += 1;
  202. }
  203. else
  204. {
  205.     j += 0;
  206. }
  207.  
  208. if (j == 3)
  209. {
  210.     printf("(6) Bob has enough money to buy any one of the three collections.\n");
  211. }
  212. else
  213. {
  214.     printf("(6) Bob does not have enough money to buy any one of the three collections.\n");
  215. }
  216.  
  217. /*##########################################
  218.   Here begins the if/else statements for (7)
  219.   ########################################## */
  220.  
  221. if (j == 0)
  222. {
  223.     printf("(7) Bob does not have enough money to buy any collection.\n");
  224. }
  225. else
  226. {
  227.     printf("(7) Bob can buy at least one collection.\n");
  228. }
  229.  
  230.     return 0;
  231.     }
RAW Paste Data
Top