Question #110886

A parking garage charges a R12.00 minimum fee to park for up to three hours. The garage charges an additional R0.90 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is R20.00. Assume that no car parks for longer than 24 hours at a time. Write a program that will calculate and print the parking charges for each of 3 customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday's receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format

Expert's answer

#include <iostream>




using namespace std;




float calculateCharges(float customer_time);




int main()

{

  int number = 3;

  float customer_fees[number];

  float customer_times[number];

  int i;

  for(i = 0; i < number; i++)

  {

    cout << "Enter the time of parking of " << i+1 << " customer: ";

    cin >> customer_times[i];

    customer_fees[i] = calculateCharges(customer_times[i]);

  }

  for(i = 0; i < number; i++)

    cout << "Customer's " << i+1 << " fee for " << customer_times[i] << " = " << customer_fees[i] << endl;

  return 0;

}




float calculateCharges(float customer_time)

{

  float amount = 12 + (0.9 * ((int)customer_time - 2));

  if(amount > 20)

    return 20;

  else return amount;

}


LATEST TUTORIALS
APPROVED BY CLIENTS