Need your inputs please

Pages: 123
Good morning, I am working on this project but I keep getting error and warnings messages. Please help.
Design and develop a program for Parking-Garage charges. A parking garage uses the
following rate for the cars, truck, and bus:
CAR BUS TRUCK
First 3 hours
0.00
First 2 hours
2.00
First 1 hours
3.75
After 3 hours
1.25 per hour
After 2 hours
2.50 per hour
After 1hours
4.50 per hour
NO OVER NIGHT PARKING.
OUTPUT DESIGN:
______________________________________
TYPE OF VEHICLE : CAR
TIME IN : HH:MM
TIME OUT: HH:MM
=========================
TOTAL TIME PARKED: HH
TOTAL CHARGES:$999.99
INPUT DESIGN:
______________________________________
TYPE OF VEHCLE:X
HOURS IN :HH
MINUTES IN :MM
HOURS OUT :HH
MINUTES OUT :MM
INPUT VALIDATION: The program should not accept time that has HH less than 0 or
greater than 23, and MM less than zero and greater than 59. Number of minutes should
be only accepted as a positive number. Only valid vehicle type “C”, “T”, or “B” should
be accepted.
IMPORTANT NOTE: If the total_minutes_parked is greater than 0, then you should
round the total_hours_parked to the next hour (add one to it.) YOU MUST USE
“FUNCTION” calls, “if/else” control structures, and “switch” structures.


Here's what I did
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// This program will calculate the parking charge for Customers who will park
// their cars in a parking garage.
// Author: 
// Date: 11/15/2016

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <stdio.h>
using namespace std;
// Function prototypes
void vehicleType(int);

int main()
{
      int Car, Bus, Truck, HourIn, HourOut, MinIn, MinOut, ChargeCar, ChargeBus, ChargeTruck, HourParkTime, MinParkTime, TotalParkTime, TotalCharges,Round, HourlyRate, HourlyCarRate, HourlyBusRate,HourlyTruckRate, vehicleType, Units;
	int Minfee;			// To hold the minimum fee
	int Hourly;			// To hold the hourly rate
	
	// Constants for Minimum Fees
	const int Minfee_Car = 0.00,
			   Minfee_Bus = 2.00,
			   Minfee_Truck = 3.75;

	// Constants for Hourly rate
	const double Hourly_CarRate = 1.25,
				 Hourly_BusRate = 2.50,
				 Hourly_TruckRate = 4.50;

	// Get infos for every vehicle entering the Parking Garage
	cout << "Please enter the vehicle Type:";
	cin >> Car, Bus, Truck;
	cout << "\nHour the vehicle entered the garage:";
	cin >> HourIn;
	cout << "\nMinute the vehicle entered the garage:";
	cin >> MinIn;
	cout << "\nHour the vehicle left the garage:";
	cin >> HourOut;
	cout << "\nMinute the vehicle left the garage:";
	cin >> MinOut;

	// Define the parking time and how the time will be counted
	if (MinOut < MinIn)
	{
		MinOut = MinOut + 60;
		HourOut = HourOut - 1;
		HourParkTime = HourOut - HourIn;
		MinParkTime = MinOut - MinIn;
	}
	else
	{
		HourParkTime = HourOut - HourIn;
		MinParkTime = MinOut - MinIn;
	}
	if (MinParkTime >= 1)
	{
		Round = HourParkTime + 1;
		TotalParkTime = Round;
	}
	else
	{
		Round = HourParkTime;
		TotalParkTime = Round;
	}
	// Validate the Time


	// Define the Hourly Rate per vehicle type 
			
	switch (vehicleType)
	{
	case 'c':
	case 'C': Units = 1;
		Minfee = Minfee_Car;
		HourlyRate = Hourly_CarRate;
		break;

	case 'b':
	case 'B': Units = 2;
		Minfee = Minfee_Bus;
		HourlyRate = Hourly_BusRate;
		break;

	case 't':
	case 'T': Units = 3;
		Minfee = Minfee_Truck;
		HourlyRate = Hourly_TruckRate;
		break;

	default: printf("\nYou did not enter a valid number");
		printf("\nHave a Nice Day!");
	}

	// Calculate the charges for each vehicle that parked in the parking garage
	int vehicleCharges;		// To hold the charges per  vehicle
	float Charges;
	if (TotalParkTime <= Units)
	{
		TotalCharges = TotalParkTime * Minfee;
	}
	else
	{
		TotalCharges = (Minfee * Units) + ((TotalParkTime - Units) * HourlyRate);
	}

	// Display the results
	cout << "vehicleType:" << vehicleType << endl;
	cout << "HourIn: HH:MM " << HourIn << endl;
	cout << "HourOut: HH:MM" << HourOut << endl;
	cout << "TotalParkTime: HH:MM" << TotalParkTime << endl;
	cout << "TotalCharges: $" << TotalCharges << endl;

	return 0;
}
Last edited on
I don't see the function definition for vehicleType and seems you have a header included that is not here either. Not sure what it is used for. You might want to prompt them to choose an option from a list possibly say 1-car 2-bus 3-truck type of thing. vehicleType(the int) is the same name as the function name, also you are comparing vehicleType as a char but it is an int. Way to many variables too, you also print an int as vehicle type at the end, this should maybe be a string that is assigned the type depending on the selection entered by user.

How do the hours work too, first 3 hours are 0.00?? For the first hour is it 3.75 an hour then the 2nd hour is 2.00, 3rd hour is free then the following hours are 1.25? Or is it cost 1.25 per hour if exceeds 3 and the rates of they were to stay only 1,2,3 hours? If that is so then if they stay 3 hours they stay for free is why i ask.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "stdafx.h" // Not sure what this is for
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath> // Dont need
#include <stdio.h> // Just use cout, you already included namespace std
using namespace std;
// Function prototypes
void vehicleType(int); // define should return a value if you want to determine something from it that is not global 


int main()
{
	// too many variables
	int Car, Bus, Truck, HourIn, HourOut, MinIn, MinOut, ChargeCar, ChargeBus, ChargeTruck, HourParkTime, MinParkTime, TotalParkTime, TotalCharges, Round, HourlyRate, HourlyCarRate, HourlyBusRate, HourlyTruckRate, vehicleType, Units;
	int Minfee;	// To hold the minimum fee --> make double
	int Hourly;	// To hold the hourly rate -->make double

				// Constants for Minimum Fees
	const int Minfee_Car = 0.00, // should be a double if you are using decimals.
		Minfee_Bus = 2.00,
		Minfee_Truck = 3.75;

	// Constants for Hourly rate
	const double Hourly_CarRate = 1.25,
		Hourly_BusRate = 2.50,
		Hourly_TruckRate = 4.50;

	// Get infos for every vehicle entering the Parking Garage
	cout << "Please enter the vehicle Type:";
	cin >> Car, Bus, Truck; // maybe create a char to take in from the user these are ints
	// char vehicle;
	// cin >> vehicle; then use that to compare below.
	cout << "\nHour the vehicle entered the garage:";
	cin >> HourIn;
	cout << "\nMinute the vehicle entered the garage:";
	cin >> MinIn;
	cout << "\nHour the vehicle left the garage:";
	cin >> HourOut;
	cout << "\nMinute the vehicle left the garage:";
	cin >> MinOut;

	// Define the parking time and how the time will be counted
	if (MinOut < MinIn) // would do if(totalmins > 0) 
	{
		MinOut = MinOut + 60; // this will violate your rules and make minutes larger than 60
		HourOut = HourOut - 1; // just increment hours like: HourParkTime++ 
		HourParkTime = HourOut - HourIn;
		MinParkTime = MinOut - MinIn;
	}
	else
	{
		HourParkTime = HourOut - HourIn;
		MinParkTime = MinOut - MinIn;
	}
	if (MinParkTime >= 1)
	{
		Round = HourParkTime + 1;
		TotalParkTime = Round;
	}
	else
	{
		Round = HourParkTime;
		TotalParkTime = Round;
	}
	// Validate the Time


	// Define the Hourly Rate per vehicle type 

	switch (vehicleType) // vehicleType should be a char
	{
	case 'c':
	case 'C': Units = 1; // units?
		Minfee = Minfee_Car;
		HourlyRate = Hourly_CarRate;
		break;

	case 'b':
	case 'B': Units = 2;
		Minfee = Minfee_Bus;
		HourlyRate = Hourly_BusRate;
		break;

	case 't':
	case 'T': Units = 3;
		Minfee = Minfee_Truck;
		HourlyRate = Hourly_TruckRate;
		break;

	default: printf("\nYou did not enter a valid number"); // I would validate as the user inputs data maybe in a while loop
		printf("\nHave a Nice Day!");						// while( input is not 'C' || 'D' || 'B') e
															// "error message" cin >> vehicleType;
	}

	// Calculate the charges for each vehicle that parked in the parking garage
	int vehicleCharges;	// To hold the charges per vehicle
	float Charges;
	if (TotalParkTime <= Units) // not sure what is purpose here parktime compared to vehicle type??
	{
		TotalCharges = TotalParkTime * Minfee;
	}
	else
	{
		TotalCharges = (Minfee * Units) + ((TotalParkTime - Units) * HourlyRate); // total charges is an int should be double
	}

	// Display the results
	cout << "vehicleType:" << vehicleType << endl; // Use regular words not variable type words
	cout << "HourIn: HH:MM " << HourIn << endl; // HourIn << ":" << MinIn <<endl;
	cout << "HourOut: HH:MM" << HourOut << endl; // same as above
	cout << "TotalParkTime: HH:MM" << TotalParkTime << endl;
	cout << "TotalCharges: $" << TotalCharges << endl; // could use decimal formatting double will only do 2.0 not 2.00

	return 0;
}

// define functions here 


Some changes that i thought about, probably more. Work on these to start.
Thanks Kyle M
#include "stdafx.h" comes with visual studio2015
Don't think you will need it, specially with one file.
https://msdn.microsoft.com/en-us/library/h552b3ca.aspx
Referring to Kyle M post:

Line 31: What are you inputting here? car, truck and bus are all ints. It looks like you're trying to ask for three ints. If so, that's not correct syntax. However, I don't think that is what you mean to do. As Kyle M suggested at line 32-33, you want to ask for the vehicle type, then make decision based on that.

You don't check that vehicle type is C, T or B as per the requirements.

You're not using functions. It is stated in the requirements that you must use functions.

Line 46-55: You need to consider the total minutes parked, not just whether minout is less than minin.

Line 9: You declared a void function vehiceType(). Not clear what this does. Nor does it appear that you ever call it or implement it.

Line 22,76,82,88: You can't store a fractional number in an int.

Line 15: vehicleType is an uninitialized variable (garbage).
Line 71: You try and make a decision based on an uninitialized variable.

Line 91-92: If you're writing C++, there is no reason to use printf. Use cout instead.

Many unused variables:
vehicleCharges, HourlyBusRatek, HourlyTruckRate, ChargeCar, Charges, Hourly, ChargeTruck, ChargeBus, HourlyCarRate
Get rid of them.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Hello! This is what I got so far but it's not giving me the correct output. Any advice please?

/ This program will calculate the parking charge for Customers who will park
// their cars in a parking garage.


#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int Car, Bus, Truck, HourIn, HourOut, MinIn, MinOut, HourParkTime, 
		MinParkTime, TotalParkTime, Round;
	double Minfee;			// To hold the minimum fee
	double TotalCharges;	// To hold the total charges
	double HourlyRate;		// To hold the hourly rate
	// Constants for Minimum Fees
	const double Minfee_Car = 0.00,   
				 Minfee_Bus = 2.00,
			     Minfee_Truck = 3.75;

	// Constants for Hourly rate
	double	Car_HourlyRate = 1.25;
	double	Bus_HourlyRate = 2.50;
	double  Truck_HourlyRate = 4.50;

	// Constants for vehicle choice
	

	// Get infos for every vehicle entering the Parking Garage
	char vehicleType;
	string vehicleText;
	cout << "Please enter the vehicle Type C, B, or T:";
	cin >> vehicleType;
	switch (vehicleType)
	{
		if (vehicleType == 'C')
		{
			vehicleText = Car;
		}
		if (vehicleType == 'B')
		{
			vehicleText = Bus;
		}
		if (vehicleType == 'T')
		{
			vehicleText = Truck;
		}

	if (vehicleType != 'C' || 'B' || 'T')
	cout << "You did not enter a valid number"
		 << "Have a Nice Day!";
	}
	// Get the time for each vehicle
	cout << "\nHour the vehicle entered the garage:";
	cin >> HourIn;
	cout << "\nMinute the vehicle entered the garage:";
	cin >> MinIn;
	cout << "\nHour the vehicle left the garage:";
	cin >> HourOut;
	cout << "\nMinute the vehicle left the garage:";
	cin >> MinOut;

	// Define the parking time and how the time will be counted
		HourParkTime = HourOut - HourIn;
	
	if (MinOut > MinIn)
		HourParkTime++;
	
	if (HourIn < 0 || HourIn > 23 || HourOut < 0 || HourOut > 23)
		cout << HourIn << HourOut << "Please enter the correct hour:";
	
	if (MinIn < 0 || MinIn > 59 || MinOut < 0 || MinOut > 59)
		cout << MinIn << MinOut << "Please enter the correct minute:";
	

	// Calculate the charges for each vehicle that parked in the parking garage
	
	if (vehicleType == 'C')
		TotalParkTime = HourParkTime - 3;

	if (TotalParkTime > 0)
	{
		TotalCharges = (TotalParkTime * Car_HourlyRate);
	}
	else
	{
		TotalCharges = 0.00;
	}

	if (vehicleType == 'B')
		TotalParkTime = HourParkTime - 2;
	if (TotalParkTime > 0)
	{
		TotalCharges = Minfee_Bus + (TotalParkTime * Bus_HourlyRate);
	}
	else
	{
		TotalCharges = 0.00;

	if (vehicleType == 'T')
		TotalParkTime = HourParkTime - 1;
	if (TotalParkTime > 0)
	{
		TotalCharges = Minfee_Truck + (TotalParkTime * Car_HourlyRate);
	}
	else
	{
		TotalCharges = 0.00;
	}
	}
	// Display the results
	cout << "vehicleType:" << vehicleType << endl;
	cout << "TimeIn: " << HourIn << ":" << MinIn << endl;
	cout << "TimeOut:" << HourOut << ":" << MinOut << endl;
	cout << "ParkTime: " << HourParkTime << endl;
	cout << "TotalCharges: $" << TotalCharges << endl;

	return 0;
} 
Last edited on
You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int Car, Bus, Truck, HourIn, HourOut, MinIn, MinOut, HourParkTime, 
		MinParkTime, TotalParkTime, Round;
	double Minfee;			// To hold the minimum fee
	double TotalCharges;	// To hold the total charges
	double HourlyRate;		// To hold the hourly rate
	// Constants for Minimum Fees
	const double Minfee_Car = 0.00,   
				 Minfee_Bus = 2.00,
			     Minfee_Truck = 3.75;

	// Constants for Hourly rate
	double	Car_HourlyRate = 1.25;
	double	Bus_HourlyRate = 2.50;
	double  Truck_HourlyRate = 4.50;

	// Constants for vehicle choice
	

	// Get infos for every vehicle entering the Parking Garage
	char vehicleType;
	string vehicleText;
	cout << "Please enter the vehicle Type C, B, or T:";
	cin >> vehicleType;
	switch (vehicleType)
	{
		if (vehicleType == 'C')
		{
			vehicleText = Car;
		}
		if (vehicleType == 'B')
		{
			vehicleText = Bus;
		}
		if (vehicleType == 'T')
		{
			vehicleText = Truck;
		}

	if (vehicleType != 'C' || 'B' || 'T')
	cout << "You did not enter a valid number"
		 << "Have a Nice Day!";
	}
	// Get the time for each vehicle
	cout << "\nHour the vehicle entered the garage:";
	cin >> HourIn;
	cout << "\nMinute the vehicle entered the garage:";
	cin >> MinIn;
	cout << "\nHour the vehicle left the garage:";
	cin >> HourOut;
	cout << "\nMinute the vehicle left the garage:";
	cin >> MinOut;

	// Define the parking time and how the time will be counted
		HourParkTime = HourOut - HourIn;
	
	if (MinOut > MinIn)
		HourParkTime++;
	
	if (HourIn < 0 || HourIn > 23 || HourOut < 0 || HourOut > 23)
		cout << HourIn << HourOut << "Please enter the correct hour:";
	
	if (MinIn < 0 || MinIn > 59 || MinOut < 0 || MinOut > 59)
		cout << MinIn << MinOut << "Please enter the correct minute:";
	

	// Calculate the charges for each vehicle that parked in the parking garage
	
	if (vehicleType == 'C')
		TotalParkTime = HourParkTime - 3;

	if (TotalParkTime > 0)
	{
		TotalCharges = (TotalParkTime * Car_HourlyRate);
	}
	else
	{
		TotalCharges = 0.00;
	}

	if (vehicleType == 'B')
		TotalParkTime = HourParkTime - 2;
	if (TotalParkTime > 0)
	{
		TotalCharges = Minfee_Bus + (TotalParkTime * Bus_HourlyRate);
	}
	else
	{
		TotalCharges = 0.00;

	if (vehicleType == 'T')
		TotalParkTime = HourParkTime - 1;
	if (TotalParkTime > 0)
	{
		TotalCharges = Minfee_Truck + (TotalParkTime * Car_HourlyRate);
	}
	else
	{
		TotalCharges = 0.00;
	}
	}
	// Display the results
	cout << "vehicleType:" << vehicleType << endl;
	cout << "TimeIn: " << HourIn << ":" << MinIn << endl;
	cout << "TimeOut:" << HourOut << ":" << MinOut << endl;
	cout << "ParkTime: " << HourParkTime << endl;
	cout << "TotalCharges: $" << TotalCharges << endl;

	return 0;
}

Sorry, here is above the code tags version. Thank you for your help
What are the integer variables Car, Bus, Truck supposed to represent? You never set them to any values, so their values are undefined.

You've defined them as integers, but at lines 34 - 45, you try and copy their (undefined) values to a string - how does that make sense? What are you really trying to achieve there?
Last edited on
Thank you for applying code tags.

Line 36,40,44: You're trying to assign int to a string.

Line 47: C++ does not support implied left hand side in conditionals. You must fully specify the conditions.
Example:
if (ans == 'Y' || 'y') evaluates as if ((ans == 'Y') || ('y'))

('y') always evaluates to 1 (true), therefore the if statement is always true.

Your switch statement has no case labels.

Your switch statement should look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	switch (vehicleType)
	{
	case 'C':   
	    vehicleText = "Car";
		break;
	case 'B':	
		vehicleText = "Bus";
		break;
    case 'T':		
	    vehicleText = "Truck";
	    break;
	default:	
        cout << "You did not enter a valid vehicle type" << endl;
	}


Line 68,71: You tell the use his input is wrong, but you don't allow him to reenter the input.

Line 81: You're computing TotalCharges based on CarHourlyRate regardless of the type of vehicle. Lines 79-86 should be conditional on line 76.

Line 92: Ditto for BusHourlyRate.

Line 102: Ditto. This should also be TruckHourlyRate.



Hello!
I am failing to find where is the issue. Need some inputs from you guys please.

Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int HourIn, HourOut, MinIn, MinOut, HourParkTime,
		TotalParkTime;

	double TotalCharges;	// To hold the total charges

							// Constants for Minimum Fees
	const double Minfee_Car = 0.00,
		Minfee_Bus = 2.00,
		Minfee_Truck = 3.75;

	// Constants for Hourly rate
	double	CarHourlyRate = 1.25;
	double	BusHourlyRate = 2.50;
	double  TruckHourlyRate = 4.50;

	// Get infos for every vehicle entering the Parking Garage
	char vehicleType;
	string vehicleText;
	cout << "Please enter the vehicle Type:";
	cin >> vehicleType;
	switch (vehicleType)
	{
	case 'C':
		vehicleText = "Car";
		break;
	case 'B':
		vehicleText = "Bus";
		break;
	case 'T':
		vehicleText = "Truck";
		break;

	default:
		cout << "You did not enter a valid vehicle type";
		return 0;
	}
	// Get the time for each vehicle
	cout << "\nHour the vehicle entered the garage:";
	cin >> HourIn;
	cout << "\nMinute the vehicle entered the garage:";
	cin >> MinIn;
	cout << "\nHour the vehicle left the garage:";
	cin >> HourOut;
	cout << "\nMinute the vehicle left the garage:";
	cin >> MinOut;

	// Define the parking time and how the time will be counted
	HourParkTime = HourOut - HourIn;

	if (MinOut > MinIn)
		HourParkTime++;

	if (HourIn < 0 || HourIn > 23 || HourOut < 0 || HourOut > 23)
		cout << "You did enter the correct time" << endl;
	if (MinIn < 0 || MinIn > 59 || MinOut < 0 || MinOut > 59)
		cout << "You did enter the correct time" << endl;


	// Calculate the charges for each vehicle that parked in the parking garage
	if ((vehicleType == 'C') && ((TotalParkTime > 3))
	{
		TotalParkTime = HourParkTime - 3
		TotalCharges = (TotalParkTime * CarHourlyRate);
	}
	
	else if ((vehicleType == 'B') && (TotalParkTime > 2))
	{
		TotalParkTime = HourParkTime - 2;
		TotalCharges = Minfee_Bus + (TotalParkTime * BusHourlyRate);
	}
	
	else if ((vehicleType == 'T') && (TotalParkTime > 1))
	{
		TotalParkTime = HourParkTime - 1;
		TotalCharges = Minfee_Truck + (TotalParkTime * TruckHourlyRate);
	}
	else
	{
		TotalCharges = 0.00;
	}

	// Display the results
	cout << "vehicleType:" << vehicleType << endl;
	cout << "TimeIn: " << HourIn << ":" << MinIn << endl;
	cout << "TimeOut:" << HourOut << ":" << MinOut << endl;
	cout << "ParkTime: " << HourParkTime << ":" << endl;
	cout << "TotalCharges: $" << TotalCharges << endl;

	return 0;
}
Please be more specific about the issues you're having.

Line 68: You have unbalanced parenthesis.

Line 70: You're missing a ;

Line 26-44: What's the purpose of vehicleText? It's not used anywhere.

Lines 56-60: You're doing calculations before you've determined if the input is valid. Not a good idea.

Lines 42,61-64: As pointed out before, you're telling the user his input is bad, but you don;t prompt the user for corrected input as per the instructions and you continue as if the data was valid.

Here's a function for accepting a valid number from the user:
1
2
3
4
5
6
7
8
9
10
int get_int (int max)
{   int     num;

    while (true)
    {   cin >> num;
        if (num >= 0 && num <= max)
            return num;
        cout << "Number must be between 0 and " << max << endl;
    }
}                


Lines 31,34,37, 68,74,80: All assume the user entered upper case.
Last edited on
I mean that I am not getting the output
You're not going to get any output until you fix your compile errors.
I think I am really confused right now and I need your help please. I an not getting any error but still can get the out put. What am I doing wrong here?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int HourIn, HourOut, MinIn, MinOut, HourParkTime,
		TotalParkTime;

	double TotalCharges;	// To hold the total charges

							// Constants for Minimum Fees
	const double Minfee_Car = 0.00,
		Minfee_Bus = 2.00,
		Minfee_Truck = 3.75;

	// Constants for Hourly rate
	double	CarHourlyRate = 1.25;
	double	BusHourlyRate = 2.50;
	double  TruckHourlyRate = 4.50;

	// Get infos for every vehicle entering the Parking Garage
	char vehicleType;
	string vehicleText;
	cout << "Please enter the vehicle Type:";
	cin >> vehicleType;
	switch (vehicleType)
	{
	case 'c':
	case 'C':
		vehicleText = "Car";
		break;
	case 'b':
	case 'B':
		vehicleText = "Bus";
		break;
	case 't':
	case 'T':
		vehicleText = "Truck";
		break;

	default:
		cout << "You did not enter a valid vehicle type";
		return 0;
	}
	// Get the time for each vehicle
	cout << "\nHour the vehicle entered the garage:";
	cin >> HourIn;
	cout << "\nMinute the vehicle entered the garage:";
	cin >> MinIn;
	cout << "\nHour the vehicle left the garage:";
	cin >> HourOut;
	cout << "\nMinute the vehicle left the garage:";
	cin >> MinOut;

	// Define the parking time and how the time will be counted
	
		HourParkTime = HourOut - HourIn;
	if (MinOut > MinIn)
		HourParkTime++;
	
	if (HourIn < 0 || HourIn > 23 || HourOut < 0 || HourOut > 23 || MinIn < 0 || MinIn > 60 || MinOut < 0 || MinOut > 60)
		cout << "You did not enter the correct time";
		return HourIn || MinIn || HourOut || MinOut;
	 

	// Calculate the charges for each vehicle that parked in the parking garage
	
	if ((vehicleType == 'C' || 'c') && (TotalParkTime > 3))
	{
		TotalParkTime = HourParkTime - 3;
		TotalCharges = (TotalParkTime * CarHourlyRate);
	}
	
	else if ((vehicleType == 'B' || 'b') && (TotalParkTime > 2))
	{
		TotalParkTime = HourParkTime - 2;
		TotalCharges = Minfee_Bus + (TotalParkTime * BusHourlyRate);
	}
	
	else if ((vehicleType == 'T' || 't') && (TotalParkTime > 1))
	{
		TotalParkTime = HourParkTime - 1;
		TotalCharges = Minfee_Truck + (TotalParkTime * TruckHourlyRate);
	}
	else
	{
		TotalCharges = 0.00;
	}

	// Display the results
	cout << "vehicleType:" << vehicleType << endl;
	cout << "TimeIn: " << HourIn << ":" << MinIn << endl;
	cout << "TimeOut:" << HourOut << ":" << MinOut << endl;
	cout << "ParkTime: " << HourParkTime << ":" << endl;
	cout << "TotalCharges: $" << TotalCharges << endl;

	return 0;
}
closed account (48T7M4Gy)
What is going wrong? Your latest code compiles and runs and a prompt appears asking for the vehicle type.
Hi Kermot!
Yes but it's not showing the Totalcharges and this is all I am getting when I am typing in some inputs

Please enter the vehicle Type:C

Hour the vehicle entered the garage:7

Minute the vehicle entered the garage:00

Hour the vehicle left the garage:9

Minute the vehicle left the garage:00
Press any key to continue . . .



It is not going further than that
Last edited on
It is not going further than that


That is because it returned (to the operating system) on line 66.
1
2
3
if (HourIn < 0 || HourIn > 23 || HourOut < 0 || HourOut > 23 || MinIn < 0 || MinIn > 60 || MinOut < 0 || MinOut > 60)
		cout << "You did not enter the correct time";
		return HourIn || MinIn || HourOut || MinOut;


Lines 65 and 66 are probably supposed to be in an if block { }.

I can't imagine what line 66 is intended to do, anyway.
Pages: 123