Guest User

Untitled

a guest
Jan 21st, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. //Declare all variables
  5. char vehicle;
  6. int inHour = 0;
  7. int inMin = 0;
  8. int outHour = 0;
  9. int outHourPrint = 0;
  10. int outMin = 0;
  11. int outMinPrint = 0;
  12. int spentHour = 0;
  13. int spentMin = 0;
  14. int roundHour = 0;
  15. int roundTotal = 0;
  16. float cost = 0;
  17.  
  18. //Ask the user what type of vehicle and use switch to handle choice
  19. printf("Type of vehicle?(C for Car, T for Truck and B for Bus): ");
  20. scanf("%c", &vehicle);
  21.  
  22. switch(vehicle)
  23. {
  24. //Car Case
  25. case('C'):
  26. //ask user to values
  27. printf("Hour vehicle entered lot(0 - 24)? ");
  28. scanf("%d", &inHour);
  29. printf("Minute vehicle entered lot(0 - 60)? ");
  30. scanf("%d", &inMin);
  31. printf("Hour vehicle left lot(0 - 24)? ");
  32. scanf("%d", &outHour);
  33. printf("Minute vehicle left lot(0 - 24)? ");
  34. scanf("%d", &outMin);
  35. printf("\n");
  36.  
  37. //Assign out times to print variables
  38. outHourPrint = outHour;
  39. outMinPrint = outMin;
  40.  
  41. //Time spent in lot calculations
  42. if(outMin < inMin){
  43. outMin = outMin + 60;
  44. outHour = outHour - 1;
  45. }
  46.  
  47. spentHour = outHour - inHour;
  48. spentMin = outMin - inMin;
  49.  
  50. //rounding time spent up
  51. if(spentMin > 0){
  52. roundHour = spentHour + 1;
  53. }
  54. else {
  55. roundHour = spentHour;
  56. }
  57.  
  58. //calculate rounded total
  59. roundTotal = 60 - spentMin;
  60.  
  61. //calculate cost for a car first and second rate
  62. if(roundHour <= 3){
  63. cost = roundHour * 0.00;
  64. }
  65. else if(roundHour > 3){
  66. cost = roundHour * 1.50;
  67. }
  68.  
  69. //Print everything
  70. printf("\t\t\tPARKING LOT CHARGES\n");
  71. printf("Type of vehicle: Car\n");
  72. printf("TIME-IN\t\t\t\t%d:%d\n", inHour, inMin);
  73. printf("TIME-OUT\t\t\t%d:%d\n", outHourPrint, outMinPrint);
  74. printf("\t\t\t\t_________\n");
  75. printf("\n");
  76. printf("PARKING TIME\t\t\t%d:00\n", roundHour);
  77. printf("ROUNDED TOTAL\t\t\t %d\n", roundTotal);
  78. printf("\t\t\t\t_________\n");
  79. printf("TOTAL CHARGES\t\t\t$%.2f\n", cost);
  80. printf("\n");
  81.  
  82. case('T'):
  83. //ask user to values
  84. printf("Hour vehicle entered lot(0 - 24)? ");
  85. scanf("%d", &inHour);
  86. printf("Minute vehicle entered lot(0 - 60)? ");
  87. scanf("%d", &inMin);
  88. printf("Hour vehicle left lot(0 - 24)? ");
  89. scanf("%d", &outHour);
  90. printf("Minute vehicle left lot(0 - 24)? ");
  91. scanf("%d", &outMin);
  92. printf("\n");
  93.  
  94. //Assign out times to print variables
  95. outHourPrint = outHour;
  96. outMinPrint = outMin;
  97.  
  98. //Time spent in lot calculations
  99. if(outMin < inMin){
  100. outMin = outMin + 60;
  101. outHour = outHour - 1;
  102. }
  103.  
  104. spentHour = outHour - inHour;
  105. spentMin = outMin - inMin;
  106.  
  107. //rounding time spent up
  108. if(spentMin > 0){
  109. roundHour = spentHour + 1;
  110. }
  111. else {
  112. roundHour = spentHour;
  113. }
  114.  
  115. //calculate rounded total
  116. roundTotal = 60 - spentMin;
  117.  
  118. //calculate cost for a car first and second rate
  119. if(roundHour <= 2){
  120. cost = roundHour * 1.00;
  121. }
  122. else if(roundHour > 2){
  123. cost = roundHour * 2.30;
  124. }
  125.  
  126. //Print everything
  127. printf("\t\t\tPARKING LOT CHARGES\n");
  128. printf("Type of vehicle: Truck\n");
  129. printf("TIME-IN\t\t\t\t%d:%d\n", inHour, inMin);
  130. printf("TIME-OUT\t\t\t%d:%d\n", outHourPrint, outMinPrint);
  131. printf("\t\t\t\t_________\n");
  132. printf("\n");
  133. printf("PARKING TIME\t\t\t%d:00\n", roundHour);
  134. printf("ROUNDED TOTAL\t\t\t %d\n", roundTotal);
  135. printf("\t\t\t\t_________\n");
  136. printf("TOTAL CHARGES\t\t\t$%.2f\n", cost);
  137. printf("\n");
  138.  
  139. //Bus Case
  140. case('B'):
  141. //ask user to values
  142. printf("Hour vehicle entered lot(0 - 24)? ");
  143. scanf("%d", &inHour);
  144. printf("Minute vehicle entered lot(0 - 60)? ");
  145. scanf("%d", &inMin);
  146. printf("Hour vehicle left lot(0 - 24)? ");
  147. scanf("%d", &outHour);
  148. printf("Minute vehicle left lot(0 - 24)? ");
  149. scanf("%d", &outMin);
  150. printf("\n");
  151.  
  152. //Assign out times to print variables
  153. outHourPrint = outHour;
  154. outMinPrint = outMin;
  155.  
  156. //Time spent in lot calculations
  157. if(outMin < inMin){
  158. outMin = outMin + 60;
  159. outHour = outHour - 1;
  160. }
  161.  
  162. spentHour = outHour - inHour;
  163. spentMin = outMin - inMin;
  164.  
  165. //rounding time spent up
  166. if(spentMin > 0){
  167. roundHour = spentHour + 1;
  168. }
  169. else {
  170. roundHour = spentHour;
  171. }
  172.  
  173. //calculate rounded total
  174. roundTotal = 60 - spentMin;
  175.  
  176. //calculate cost for a car first and second rate
  177. if(roundHour <= 1){
  178. cost = roundHour * 2.00;
  179. }
  180. else if(roundHour > 1){
  181. cost = roundHour * 3.70;
  182. }
  183.  
  184. //Print everything
  185. printf("\t\t\tPARKING LOT CHARGES\n");
  186. printf("Type of vehicle: Bus\n");
  187. printf("TIME-IN\t\t\t\t%d:%d\n", inHour, inMin);
  188. printf("TIME-OUT\t\t\t%d:%d\n", outHourPrint, outMinPrint);
  189. printf("\t\t\t\t_________\n");
  190. printf("\n");
  191. printf("PARKING TIME\t\t\t%d:00\n", roundHour);
  192. printf("ROUNDED TOTAL\t\t\t %d\n", roundTotal);
  193. printf("\t\t\t\t_________\n");
  194. printf("TOTAL CHARGES\t\t\t$%.2f\n", cost);
  195. printf("\n");
  196. }
  197. return 0;
  198. }
Add Comment
Please, Sign In to add comment