Question

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 for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car is 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 eached customer. Your program should print the results in a tabular format and slould calculate and print the total of yesterday's receipts. The program should have a function named calculateCharges to determine the charge for each customer. Your outputs should appear in the following format: I don't know what I'm doing wrong.

#include <iostream>

#include <iomanip>

#include <cstdlib>

#include <cmath>

using std::cout;

using std::endl;

using std::cin;

using std::setw;

double calculateCharges( double );

int main() {

double charge = 0;

double hours = 0;

double total;

double cars;

double car1, car2, car3;

cout << "Enter Hours for Car1: " << car1 << endl;

cin >> car1;

cout << "Enter Hours for Car2: " << car2 << endl;

cin >> car2;

cout << "Enter Hours for Car3: " << car3 << endl;

cin >> car3;

  cout << "Charge Car1: " << car1 << endl;

cout << "Charge Car2: " << car2 << endl;

cout << "Charge Car3: " << car3 << endl;

   

         

cout << "Cars" << setw( 13 ) << "Hours" << setw( 13 ) << "Charge" << endl;

cout << "   1" << setw( 13 ) << car1 << endl;

cout << "   2" << setw( 13 ) << car2 << endl;

cout << "   3" << setw( 13 ) << car3 << endl;

return 0;

}

double calculateCharges( double ){

double hours = 3, charge = 2.00;

if (hours <= 3)

charge = 2.00;

else if (hours >= 24)

charge = 2.50;

else

charge = 10.00;

return charge;

}

Homework Answers

Answer #1

Note

#######

The program is updated. Function to calculate parking charge was wrong. Please go through the code

//##################### PGM START ##################

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>

using std::cout;
using std::endl;
using std::cin;
using std::setw;

double calculateCharges( double );

int main() {

   double total;
   double car1, car2, car3;

   cout << "Enter Hours for Car1: ";
   cin >> car1;

   cout << "Enter Hours for Car2: ";
   cin >> car2;

   cout << "Enter Hours for Car3: ";
   cin >> car3;


   total=calculateCharges(car1)+calculateCharges(car2)+calculateCharges(car3);

   cout << "Cars" << setw( 13 ) << "Hours" << setw( 13 ) << "Charge($)" << endl;
   cout << "   1" << setw( 13 ) << car1 << setw( 13 ) << calculateCharges(car1)<<endl;
   cout << "   2" << setw( 13 ) << car2 << setw( 13 ) << calculateCharges(car2)<<endl;
   cout << "   3" << setw( 13 ) << car3 << setw( 13 ) << calculateCharges(car3)<<endl;
   cout<<"\nTotal Parking Charge: "<<setw(8)<<total<<"\n";

   return 0;

}
//function to claculate parking charge was wrong
double calculateCharges( double hours ){

   double charge = 2.00;

  
   if (hours <= 3)
       charge = 2.00;
   else if (hours >= 24)
       charge = 10;
   else
       charge+=((hours-3)*0.5);
   return charge;

}

//############################# PGM END ##########################
OUTPUT
#########

Know the answer?
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
Similar Questions
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the values for hours, minutes and seconds are a legal military time (i.e. 00 00 00 to 23 59 59) the program should display the formatted results (i.e. 12 34 56 should be displayed as 12:34:56). If there's an error for any of the entered values, an exception should be thrown and an error message should be displayed. Note, there are three exception conditions, one...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
n this lab, you use what you have learned about parallel arrays to complete a partially...
n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should: Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop Or it should print the message Sorry, we do not carry that. Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the...