Hello. I'm still fairly new with C++.
I started on a code with a friend, but I'm still very unsure about setting up loops and such.
Some help on where to go next with this problem would be much appreciated!

This program requires you to input information about vehicles in a parking lot and calculate their bill for parking. The input for a vehicle will consist of a character and four integer values.
The character will be either C, T, or B; this indicates car, truck, or bus.

The first integer ( 0 <= hr_in < 24) will represent the hour of the arrival time of the vehicle
The second integer ( 0 <= min_in < 60) will represent the minutes of the arrival time of the vehicle
The third integer ( 0 <= hr_out < 24) will represent the hour of the departure time of the vehicle
The fourth integer ( 0 <= min_out < 60) will represent the minutes of the departure time of the vehicle

For example C 10 30 13 0

A car arrived at 10:30 and left at 13:00.

Parking fees are detailed in the table that follows:

Type of vehicle Initial rate Rate for additional time
Car First 3 hours are free
$1.50 per hour after the first 3
Truck First 2 hours cost $2.50
$5.00 per hour after the first 2
Bus First hour costs $5.00 $7.50 per hour after the first

this is what I have so far.....

#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
   
   
   
    
 if(a=='C'){
            
   cout<<"What hour did they arrive?"<<endl;
   cin>>integar1;
   cout<<"What minute did they arrive?"<<endl;
   cin>>integar2;
   cout<<"What hour did they depart?"<<endl;
   cin>>integar3;
   cout<<"What minute did they depart?"<<endl;
   cin>>integar4;
  
   double arrive = integar1 + (integar2/100);
   double depart = integar3 + (integar4/100);
   double duration = depart - arrive;
   //If statement for first 3 hours
   if (duration <= 3.0){
   cout<<"****************************"<<endl;
   cout<<"   Parking Garage Charges   "<<endl;
   cout<<"****************************"<<endl;
               
                cout<<"No Charge"<<endl;
                }
  
   if (duration > 3.0){
   double cost = (duration - 3.0) * 1.50;
  
   cout<<"============================"<<endl;
   cout<<"   Parking Garage Charges   "<<endl;
   cout<<"============================"<<endl;
  
  
   cout<<"Arrived at:" << " " << arrive << " " << "Departed" << " " << depart <<endl;
   cout<<"Duration" << " " << setprecision(2)<< duration << " " << "hours"<<endl;
   cout<<"Cost:" << " " << setprecision(2)<< cost << " " << "dollars"<<endl;
}

Edited 6 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

double arrive = integar1 + (integar2/100);
double depart = integar3 + (integar4/100);

What portion of an hour is 30 minutes? It's surely not 0.3.

Otherwise just go ahead and do the portion for the truck.

(and just a nitpicky thing but you don't need to include fstream)

Edited 6 Years Ago by jonsca: n/a

#include <fstream>
#include <iomanip>
#include <conio.h>
#include <iostream>
 
//using namespace std;
 
int main()
{
  char a;
  int integar1,integar2,integar3,integar4;
  cout<<"Do you want to continue?\n";
  cin>>a;
 
 if(a=='C')
 {
 
   cout<<"What hour did they arrive?"<<endl;
   cin>>integar1;
   cout<<"What minute did they arrive?"<<endl;
   cin>>integar2;
   cout<<"What hour did they depart?"<<endl;
   cin>>integar3;
   cout<<"What minute did they depart?"<<endl;
   cin>>integar4;
 
   double arrive = integar1 + (integar2/100);
   double depart = integar3 + (integar4/100);
   double duration = depart - arrive;
   //If statement for first 3 hours
   if (duration <= 3.0){
   cout<<"****************************"<<endl;
   cout<<"   Parking Garage Charges   "<<endl;
   cout<<"****************************"<<endl;
 
                cout<<"No Charge"<<endl;
                }
 
   if (duration > 3.0){
   double cost = (duration - 3.0) * 1.50;
 
   cout<<"============================"<<endl;
   cout<<"   Parking Garage Charges   "<<endl;
   cout<<"============================"<<endl;
 
 
   cout<<"Arrived at:" << " " << arrive << " " << "Departed" << " " << depart <<endl;
   cout<<"Duration" << " " << setprecision(2)<< duration << " " << "hours"<<endl;
   cout<<"Cost:" << " " << setprecision(2)<< cost << " " << "dollars"<<endl;
 }
 }
 getch();
 return 0;
}

This is the correct coding mention above!

Edited 6 Years Ago by Nick Evan: Added code-tags

Just a thought, if you divide the cost per hour into a cost per minute you can make all your code integer multiplication and addition with a few subtractions. I dont know if you want to do that kind of simplification but as i said was just a thought. You seem to be doing a good job so carry on :)

This article has been dead for over six months. Start a new discussion instead.