Question

Write a program in C An international airport offers long term parking at the following rates:...

Write a program in C

An international airport offers long term parking at the following rates:

First 60 minutes is free;

61-80 minutes $4;

Each additional 20 minutes $2;

And $18 max. per day (24 hours).

Write a program longterm_parking.c that calculates and prints the charges for parking at the long term parking garage.

1. The user enters the number of total hours and minutes; the program prints the charge.

2. If the input is invalid, print a message and exit the program.

Example input/output:

Enter hours parked: 26

Enter minutes parked: 28

Amount due ($): $34

Example input/output:

Enter hours parked: 50

Enter minutes parked: 2

Amount due ($): $50

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Screenshots:

Sample Output;

Code to Copy:

// Include the necessary header files.

#include <stdio.h>

#include <stdlib.h>

// Definition of the function.

int next_Day_Amt(int mins){

int Amt;

// Check the condition.

if(mins>220)

return 18;

else{

Amt = (mins / 20) * 2 ;

// Check the condition.

if((mins % 20) != 0)

return (Amt+2);

// Return value.

return Amt;

}

}

// Definition of the method.

int Cal_Amt(int Hrs, int mins){

// Declare variables.

int T_mins, Amt;

T_mins = Hrs*60 + mins ;

// Check the condition.

if(T_mins >= 0 && T_mins <= 60)

return 0;

else

// Check the condition.

if(T_mins >= 61 && T_mins <= 80)

return 4;

else

// Check the condition

if(T_mins >= 81 && T_mins <= 220){

T_mins -= 80 ;

Amt = (T_mins / 20) * 2 + 4;

//Check the condition.

if((T_mins % 20) != 0)

return (Amt+2);

return Amt;

}

else

//Check the condition.

if(T_mins >= 220 && T_mins <= (24*60))

return 18;

else {

// Calculate value

Amt = (T_mins / (24*60)) * 18 ;

return Amt + next_Day_Amt(T_mins % (24*60));

}

}

int main(){

int Hrs=0, mins=0, Amt=0 ;

// prompt the user to enter hrs

printf("\nEnter Hours parked: ");

scanf("%d",&Hrs);

// prompt the user to enter minutes.

printf("\nEnter minutes parked: ");

scanf("%d",&mins);

// Check the condition.

if(mins > 59){

printf("\nmins should be under 59");

exit(0);

}

// Call the function

Amt = Cal_Amt(Hrs,mins);

// Display amount

printf("\nAmount due ($): $%d\n",Amt);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Write a program in C An international airport offers long term parking at the following rates:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ console application that calculates and displays the charges for multiple customers using a...

    Write a C++ console application that calculates and displays the charges for multiple customers using a parking garage. The parking garage charges a minimum fee of $3.00 to park for up to three hours. The garage charges an additional $0.85 per hour or fraction of an hour for parking over three hours. The maximum charge for any given 24-hour period is $20.00. You may assume that no car parks for longer than 24 hours at a time. Your program will...

  • A parking garage charges a $2.00 minimum fee to park for up to three hours. The...

    A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour in excess of these initial three hours. The maximum charge for any given 24 hour period is $10.00. Assume no car parks for longer than 24 hours at a time. Write a program that calculates and prints the total parking charges for the customers who parked their cars in this garage (at least 4 cars) and the...

  • Assignment: My friend, Cary Parker, owns a small parking garage downtown. She wants you to write...

    Assignment: My friend, Cary Parker, owns a small parking garage downtown. She wants you to write a program to help her calculate the parking charge at the payment booth. The price to park in the lot is $5.50 per hour, plus city parking tax. However, partial hours (even one minute into an additional hour) are charged at the full hour’s rate. For example, if you park for exactly 60 minutes, or less, you will pay $5.50 plus tax, but if...

  • Matlab Most major airports hgve separate lots for long-term and short-term park- ing. The cost to...

    Matlab Most major airports hgve separate lots for long-term and short-term park- ing. The cost to park depends on the lot you select, and how long you stay Consider this rate structure from the Salt Lake International Airport during the summer of 2016. 8.20 Long-Term (Economy) Parking o The first hour is $2.00, and each additional hour or fraction thereof is $1.00 o Daily maximum $9.00 o Weekly maximum $60.00 . Short-Term Parking 。The first 30 minutes are $2.00 and...

  • Write a program that calculates and prints the number of minutes in a year. Assume the...

    Write a program that calculates and prints the number of minutes in a year. Assume the following: 1 year = 365 days (Ignore leap years) 1 day = 24 hours 1 hour = 60 minutes Below is an example of the correct output format: The number of minutes in a year is X

  • Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need...

    Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example in the PPT) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked beyond their time...

  • The Bashemin Parking Garage contains a single lane that can hold up to ten cars. Arriving...

    The Bashemin Parking Garage contains a single lane that can hold up to ten cars. Arriving cars enter the garage at the rear and are parked in the empty space nearest to the front. Departing cars exit only from the front. If a customer needs to pick up a car that is not nearest to the exit, then all cars blocking its path are moved out temporarily, the customer's car is driven out, and the other cars are restored in...

  • Write the following code in C. Write a program that takes a positive integer and prints...

    Write the following code in C. Write a program that takes a positive integer and prints that many stars These are sample outputs. Enter the number of stars: 9 Enter the number of stars: 4 Enter the number of stars: -3 Invalid input!

  • in c++ program Write a C + + program that prompts the user to input the...

    in c++ program Write a C + + program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example, if the elapsed time is 9630 seconds, then the output is 2:40:30.)

  • this is a C++ program! You will write a program that performs the following tasks for...

    this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT