Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method that takes a parameter for the number of minutes parked (you can

ID: 3673965 • Letter: W

Question

Write a method that takes a parameter for the number of minutes parked (you can assume it's a whole number and returns the appropriate short-term parking charge, in dollars. Assume that the airport will always round UP to the next half-hour - for example, parking exactly 60 minutes would cost $2, but 61 minutes would make it $3. After all, they want to make as much money as possible!

If the method is called with a zero or negative argument, maie it return zero. If the method is called with an argument exceeding 24 hours, make it return the 24-hour maximum listed in the table.

Explanation / Answer


#include <stdio.h>
#include <math.h>

int check(int m)
{
    if(m<=0)
        return 0;

    if(m>=24*60)
        return 24*2;

    return ceil(m*1.0/30);

}


int main()
{
    printf("%d ", check(61));
    printf("%d ", check(60));  
    printf("%d ", check(25*60));
    printf("%d ", check(24*60));
    printf("%d ", check(0));
    printf("%d ", check(-5));

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote