Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(){
- //Declare all variables
- char vehicle;
- int inHour = 0;
- int inMin = 0;
- int outHour = 0;
- int outHourPrint = 0;
- int outMin = 0;
- int outMinPrint = 0;
- int spentHour = 0;
- int spentMin = 0;
- int roundHour = 0;
- int roundTotal = 0;
- float cost = 0;
- //Ask the user what type of vehicle and use switch to handle choice
- printf("Type of vehicle?(C for Car, T for Truck and B for Bus): ");
- scanf("%c", &vehicle);
- switch(vehicle)
- {
- //Car Case
- case('C'):
- //ask user to values
- printf("Hour vehicle entered lot(0 - 24)? ");
- scanf("%d", &inHour);
- printf("Minute vehicle entered lot(0 - 60)? ");
- scanf("%d", &inMin);
- printf("Hour vehicle left lot(0 - 24)? ");
- scanf("%d", &outHour);
- printf("Minute vehicle left lot(0 - 24)? ");
- scanf("%d", &outMin);
- printf("\n");
- //Assign out times to print variables
- outHourPrint = outHour;
- outMinPrint = outMin;
- //Time spent in lot calculations
- if(outMin < inMin){
- outMin = outMin + 60;
- outHour = outHour - 1;
- }
- spentHour = outHour - inHour;
- spentMin = outMin - inMin;
- //rounding time spent up
- if(spentMin > 0){
- roundHour = spentHour + 1;
- }
- else {
- roundHour = spentHour;
- }
- //calculate rounded total
- roundTotal = 60 - spentMin;
- //calculate cost for a car first and second rate
- if(roundHour <= 3){
- cost = roundHour * 0.00;
- }
- else if(roundHour > 3){
- cost = roundHour * 1.50;
- }
- //Print everything
- printf("\t\t\tPARKING LOT CHARGES\n");
- printf("Type of vehicle: Car\n");
- printf("TIME-IN\t\t\t\t%d:%d\n", inHour, inMin);
- printf("TIME-OUT\t\t\t%d:%d\n", outHourPrint, outMinPrint);
- printf("\t\t\t\t_________\n");
- printf("\n");
- printf("PARKING TIME\t\t\t%d:00\n", roundHour);
- printf("ROUNDED TOTAL\t\t\t %d\n", roundTotal);
- printf("\t\t\t\t_________\n");
- printf("TOTAL CHARGES\t\t\t$%.2f\n", cost);
- printf("\n");
- case('T'):
- //ask user to values
- printf("Hour vehicle entered lot(0 - 24)? ");
- scanf("%d", &inHour);
- printf("Minute vehicle entered lot(0 - 60)? ");
- scanf("%d", &inMin);
- printf("Hour vehicle left lot(0 - 24)? ");
- scanf("%d", &outHour);
- printf("Minute vehicle left lot(0 - 24)? ");
- scanf("%d", &outMin);
- printf("\n");
- //Assign out times to print variables
- outHourPrint = outHour;
- outMinPrint = outMin;
- //Time spent in lot calculations
- if(outMin < inMin){
- outMin = outMin + 60;
- outHour = outHour - 1;
- }
- spentHour = outHour - inHour;
- spentMin = outMin - inMin;
- //rounding time spent up
- if(spentMin > 0){
- roundHour = spentHour + 1;
- }
- else {
- roundHour = spentHour;
- }
- //calculate rounded total
- roundTotal = 60 - spentMin;
- //calculate cost for a car first and second rate
- if(roundHour <= 2){
- cost = roundHour * 1.00;
- }
- else if(roundHour > 2){
- cost = roundHour * 2.30;
- }
- //Print everything
- printf("\t\t\tPARKING LOT CHARGES\n");
- printf("Type of vehicle: Truck\n");
- printf("TIME-IN\t\t\t\t%d:%d\n", inHour, inMin);
- printf("TIME-OUT\t\t\t%d:%d\n", outHourPrint, outMinPrint);
- printf("\t\t\t\t_________\n");
- printf("\n");
- printf("PARKING TIME\t\t\t%d:00\n", roundHour);
- printf("ROUNDED TOTAL\t\t\t %d\n", roundTotal);
- printf("\t\t\t\t_________\n");
- printf("TOTAL CHARGES\t\t\t$%.2f\n", cost);
- printf("\n");
- //Bus Case
- case('B'):
- //ask user to values
- printf("Hour vehicle entered lot(0 - 24)? ");
- scanf("%d", &inHour);
- printf("Minute vehicle entered lot(0 - 60)? ");
- scanf("%d", &inMin);
- printf("Hour vehicle left lot(0 - 24)? ");
- scanf("%d", &outHour);
- printf("Minute vehicle left lot(0 - 24)? ");
- scanf("%d", &outMin);
- printf("\n");
- //Assign out times to print variables
- outHourPrint = outHour;
- outMinPrint = outMin;
- //Time spent in lot calculations
- if(outMin < inMin){
- outMin = outMin + 60;
- outHour = outHour - 1;
- }
- spentHour = outHour - inHour;
- spentMin = outMin - inMin;
- //rounding time spent up
- if(spentMin > 0){
- roundHour = spentHour + 1;
- }
- else {
- roundHour = spentHour;
- }
- //calculate rounded total
- roundTotal = 60 - spentMin;
- //calculate cost for a car first and second rate
- if(roundHour <= 1){
- cost = roundHour * 2.00;
- }
- else if(roundHour > 1){
- cost = roundHour * 3.70;
- }
- //Print everything
- printf("\t\t\tPARKING LOT CHARGES\n");
- printf("Type of vehicle: Bus\n");
- printf("TIME-IN\t\t\t\t%d:%d\n", inHour, inMin);
- printf("TIME-OUT\t\t\t%d:%d\n", outHourPrint, outMinPrint);
- printf("\t\t\t\t_________\n");
- printf("\n");
- printf("PARKING TIME\t\t\t%d:00\n", roundHour);
- printf("ROUNDED TOTAL\t\t\t %d\n", roundTotal);
- printf("\t\t\t\t_________\n");
- printf("TOTAL CHARGES\t\t\t$%.2f\n", cost);
- printf("\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment