Guest User

Untitled

a guest
Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main(){
  4. //Declare variables
  5. char vehicleType;
  6. int hourVehicleEnter, minuteVehicleEnter, hourVehicleLeft, minuteVehicleLeft, timeInHour, timeInMin;
  7. float firstRate = 0, secondRate = 0, totalRate = 0;
  8.  
  9. //Ask the user to enter car type and time
  10. printf("Enter the type of vehicle: ");
  11. scanf("%c", &vehicleType);
  12. printf("Enter the hour the vehicle entered the lot(0-24): ");
  13. scanf("%d", &hourVehicleEnter);
  14. printf("Enter the minute the vehicle entered the lot(0-60): ");
  15. scanf("%d", &minuteVehicleEnter);
  16. printf("Enter the hour the vehicle left the lot(0-24): ");
  17. scanf("%d", &hourVehicleLeft);
  18. printf("Enter the minute the vehicle left the lot(0-60): ");
  19. scanf("%d", &minuteVehicleLeft);
  20.  
  21. //Calculate time difference
  22. timeInHour = abs(hourVehicleLeft - hourVehicleEnter);
  23. timeInMin = 60 - (abs(minuteVehicleLeft - minuteVehicleEnter));
  24.  
  25. //Round up hours
  26. if(timeInMin > 0){
  27. timeInHour++;
  28. }
  29.  
  30. //Calculate the rate based on the vehicle choice
  31. if((vehicleType == 'C') || (vehicleType == 'c')){
  32. if(timeInHour > 3){
  33. secondRate = 1.50 * (timeInHour - 3);
  34. }else{
  35. firstRate = 0;
  36. }
  37. totalRate = secondRate + firstRate;
  38. //Output the result
  39. printf("Type of Vehicle: Car");
  40. printf("\nTIME-IN: %d : %d ", hourVehicleEnter, minuteVehicleEnter);
  41. printf("\nTIME-OUT: %d : %d ", hourVehicleLeft, minuteVehicleLeft);
  42. printf("\n-------");
  43. printf("\nPARKING TIME: %d : %d ", (timeInHour - 1), timeInMin);
  44. printf("\nROUNDED TOTAL: %d", timeInHour);
  45. printf("\n-------");
  46. printf("\nTOTAL CHARGES: $%.2f", totalRate);
  47. }
  48.  
  49. if((vehicleType == 'T') || (vehicleType == 't')){
  50. if(timeInHour > 2){
  51. secondRate = 2.30 * (timeInHour - 2) + 2;
  52. }else{
  53. firstRate = 1.00 * timeInHour;
  54. }
  55. totalRate = secondRate + firstRate;
  56. //Output the result
  57. printf("Type of Vehicle: Truck");
  58. printf("\nTIME-IN: %d : %d ", hourVehicleEnter, minuteVehicleEnter);
  59. printf("\nTIME-OUT: %d : %d ", hourVehicleLeft, minuteVehicleLeft);
  60. printf("\n-------");
  61. printf("\nPARKING TIME: %d : %d ", (timeInHour - 1), timeInMin);
  62. printf("\nROUNDED TOTAL: %d", timeInHour);
  63. printf("\n-------");
  64. printf("\nTOTAL CHARGES: $%.2f", totalRate);
  65. }
  66.  
  67. if((vehicleType == 'B') || (vehicleType == 'b')){
  68. if(timeInHour > 1){
  69. secondRate = 3.70 * (timeInHour -1) + 2;
  70. }else{
  71. firstRate = 2.00 * timeInHour;
  72. }
  73. totalRate = secondRate + firstRate;
  74. //Output the result
  75. printf("Type of Vehicle: Bus");
  76. printf("\nTIME-IN: %d : %d ", hourVehicleEnter, minuteVehicleEnter);
  77. printf("\nTIME-OUT: %d : %d ", hourVehicleLeft, minuteVehicleLeft);
  78. printf("\n-------");
  79. printf("\nPARKING TIME: %d : %d ", (timeInHour - 1), timeInMin);
  80. printf("\nROUNDED TOTAL: %d", timeInHour);
  81. printf("\n-------");
  82. printf("\nTOTAL CHARGES: $%.2f", totalRate);
  83. }
  84. return 0;
  85. }
Add Comment
Please, Sign In to add comment