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
  • 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...

  • 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!

  • 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...

  • 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.)

  • with explanation Write a C++ program that calculates and prints the average of several integers. Assume...

    with explanation Write a C++ program that calculates and prints the average of several integers. Assume that the last value read with cin >> is the number 9999. For example, for an input sequence: 10 8 11 7 9 9999 The output should be 9.00

  • write in C++ Problem 1: Mobile Service Provider A cell phone service provider has three different...

    write in C++ Problem 1: Mobile Service Provider A cell phone service provider has three different subscription packages for its customers. Package A: For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute. Package B: For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute. Package C: For $69.99 per month unlimited minutes provided. Write a program that calculates a customer’s monthly bill. It should ask which package the customer has purchased...

  • C++ program Please only (if) (else) statements No while statements use Write a program that takes...

    C++ program Please only (if) (else) statements No while statements use Write a program that takes rate and outputs the employee's wages for the week input employee's hours worked and regular pay as an Calculate employee's wages as follows: She receives her regular rate for the an first 40 hours, 1.5 times her regular rate for each hour between 40 and 50 hours, and double her regular rate for each hour over 50. For invalid inputs, in addition to outputting...

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
ADVERTISEMENT