Garage Program help??

Hey guys i am having problems with this code and keep getting errors. After a week of going at it I still cant get it to work. Someone please help me -.-

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
 #include <iostream>
 using namespace std;

 //constants for rates
 #define firstCarRate 0.00 //first rate for cars.
 #define secondCarRate 1.25 //second rate for cars.
 #define firstTruckRate 3.75 //first rate for trucks.
 #define secondTruckRate 4.50 //second rate for trucks.
 #define firstBusRate 2.00 //first rate for buses.
 #define secondBusRate 2.50 //second rate for buses.

 //getInfo Function Prototype.
 void getInfo(char *vehicle, int *hourIn, int *minIn, int *hourOut, int *minOut);

 //time function prototype.
 void time(int hourIn, int minIn, int hourOut, int minOut, int *houtParkTime, int * minParkTime, int *roundedTotal, int *round);

 //rate function prototype.
 void rate(char vehicle, int *units, float *firstRate, float *secondRate);

 //charge function prototype.
 void charge(int roundedTotal, int units, float firstRate, float secondRate, float *totalCharge);

 //print bill function prototype.
 void printBill (char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge);

 //global variables
 char vehicle; 
 int units;
 int hourIn;
 int minIn;
 int hourOut; 
 int minOut; 
 int hourParkTime; 
 int minParkTime;
 int roundedTotal; 
 int round; 
 float firstRate; 
 float secondRate; 
 float totalCharge;

 int main(void)
 {
 getInfo(&vehicle, &hourIn, &minIn, &hourOut, &minOut);
 time(hourIn, minIn, hourOut, minOut, &hourParkTime, &minParkTime, &roundedTotal, &round);
 rate(vehicle, &units, &firstRate, &secondRate);
 charge(roundedTotal, units, firstRate, secondRate, &totalCharge);
 printBill(vehicle, hourIn, minIn, hourOut, minOut, hourParkTime, minParkTime, roundedTotal, totalCharge);
 return 0;
 }//end of main.

 //function definition for get info.
 void getInfo(char *vehicle, int *hourIn, int minIn, int *hourOut, int *minOut)
 {
 cout << "\nType of vehicle? ";
 cout << "\n(enter C for car,T for truck or B for bus).";
 cin >> vehicle;
 //check for valid vehicle type
 {
 switch(*vehicle)
 {
 {
 case 'C': cout << "You entered C.\n";
 case 'c': cout << "You entered c.\n";
 break;
 case 'T': cout << "You entered T.\n";
 case 't': cout << "You entered t.\n";
 break;
 case 'B': cout << "You entered B.\n";
 case 'b': cout << "You entered b.\n";
 break;
 default: cout << "You did not enter a valid vehicle type\n";
 cout << "Please Enter C,c,T,t,B, or b\n";

 return;
 }

 //get the hour that the vehicle entered the garage.
 cout << "\nHour vehicle entered garage? ";
 cin >> *hourIn;
 //validate input for hourIn
 if(*hourIn < 0 || *hourIn < 23)
 {
 cout << "invalid input. enter an integer between 0 and 23.";

 }

 //get the minute that the vehicle entered the garage.
 cout << "\nMinute vehicle entered garage? ";
 cin >> minIn;
 //validate input for minIn.
 if(minIn < 0 || minIn > 60)
 {
 cout << "invalid input. enter a number between 0 and 60.";
 }

 //get the hour vehicle exits garage.
 cout <<"\nHour vehicle exits garage? ";
 cin >> *hourOut;
 //validate input for hourOut.
 if(*hourOut < 0 || *hourOut < 23)
 {
 cout << "invalid input. enter an integer between 0 and 23.";
 }

 //get the minute vehicle exits garage.
 cout << "\nMinute vehicle exits garage?";
 cin >> *minOut;
 //validate input for minOut.
 if(minOut < 0 || *minOut > 60)
 {
 cout << "invalid input. enter a number between 0 and 60.";

 return;
 }
 }
 //function definition for time.
 void time(int hourIn, int minIn, int hourOut, int minOut, int *hourParkTime, int *minParkime, int *roundedTotal, int *rounded)
 {
 if (*minOut < minIn)
 {
 minOut = minOut + 60;
 hourOut = hourOut - 1;
 }
 else
 {
 hourParkTime = hourOut - hourIn;
 minParkTime = *minOut - minIn;
 }
 if(minParkTime >= 1)
 {
 round = hourParkTime + 1;
 }
 else
 {
 round = hourParkTime;
 }
 roundedTotal = round;
 return;
 }
 //Function definition for rate.
 void rate(char vehicle, int *units, float *firstRate, float *secondRate)
 {
 switch(*vehicle)
 {
 {
 case 'c':
 case 'C': units = 3;
 firstRate = firstCarRate;
 break;
 }
 {
 case 't':
 case 'T': units = 1;
 firstRate = firstTruckRate;
 secondRate = secondTruckRate;
 break;
 }
 case 'b':
 case 'B': units = 2;
 firstRate = firstBusRate;
 secondRate = secondBusRate;
 break;

 {
 default:
 cout << "\nEnter a valid vehicle type.";

 return;
 }
 //Function definition for charge.
 void charge(int roundedTotal, int units, float firtsRate, float secondRate, float totalCharges)
 if(roundedTotal <= units)
 {
 totalCharge = (roundedTotal * firstRate);
 }
 else
 {
 totalCharge = (roundedTotal - units) * (secondRate) + (units * firstRate);

 return;
 }

 //Function definition for print Bill.
 void printBill(char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge)
 {
 cout << "Vehicle Type:/t/t"<< vehicle <<endl;
 cout << "Time In:/t/t" <<hourIn<<":"<<minIn <<endl;
 cout << "Time Out:/t/t" <<hourOut<<":"<<minOut <<endl;
 cout << "Total Park Time:/t/t" <<roundedTotal <<endl;
 cout << "Total Charge:/t/t" <<totalCharge<<endl;
 return;
 } 
Line 120: This isn't a pointer, so why are you dereferencing it?
Line 126: You have a pointer here, so why aren't you dereferencing it?

You will definitely want to look through your code for similar pointer issues.

You have bracket mismatches on the following lines:
161 (close brackets missing)
171 (close brackets missing)
173 (open bracket missing)
182 (close bracket missing)

Good luck.

-Albatross
closed account (18hRX9L8)
Albatross's code (EX):

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>

//constants for rates
static const float firstCarRate = 0.00; //first rate for cars.
static const float secondCarRate = 1.25; //second rate for cars.
static const float firstTruckRate = 3.75; //first rate for trucks.
static const float secondTruckRate = 4.50; //second rate for trucks.
static const float firstBusRate = 2.00; //first rate for buses.
static const float secondBusRate = 2.50; //second rate for buses.

//function definition for get info.
void getInfo(char *vehicle, int *hourIn, int *minIn, int *hourOut, int *minOut) {
	while(true) {
		std::cout << "\nType of vehicle (enter C for car, T for truck, or B for bus)? ";
		std::cin >> vehicle;
		
		if(*vehicle == 'C' || *vehicle == 'c' || *vehicle == 'T' || *vehicle == 't' || *vehicle == 'B' || *vehicle == 'b') {
			std::cout << "You entered " << *vehicle << "\n";;
			break;
		}
		
		std::cout << "You did not enter a valid vehicle type.\nPlease Enter C, c, T, t, B, or b.\n";
	}
	
	//get the hour that the vehicle entered the garage.
	while(true) {
		std::cout << "Hour vehicle entered garage? ";
		std::cin >> *hourIn;
		
		//validate input for hourIn
		if(*hourIn < 0 || *hourIn > 23) {
			std::cout << "Invalid input. Please enter an integer between 0 and 23.\n";
		} else {
			break;
		}
	}
	
	//get the minute that the vehicle entered the garage.
	while(true) {
		std::cout << "Minute vehicle entered garage? ";
		std::cin >> *minIn;
		
		//validate input for minIn.
		if(*minIn < 0 || *minIn > 60) {
			std::cout << "Invalid input. Please enter a number between 0 and 60.\n";
		} else {
			break;
		}
	}
	
	//get the hour vehicle exits garage.
	while(true) {
		std::cout <<"Hour vehicle exits garage? ";
		std::cin >> *hourOut;
		
		//validate input for hourOut.
		if(*hourOut < 0 || *hourOut > 23) {
			std::cout << "Invalid input. Please enter an integer between 0 and 23.\n";
		} else {
			break;
		}
	}
	
	//get the minute vehicle exits garage.
	while(true) {
		std::cout << "Minute vehicle exits garage?";
		std::cin >> *minOut;
		
		//validate input for minOut.
		if(minOut < 0 || *minOut > 60) {
			std::cout << "Invalid input. Please enter a number between 0 and 60.\n";
		} else {
			break;
		}
	}
}

//function definition for time.
void time(int *hourIn, int *minIn, int *hourOut, int *minOut, int *hourParkTime, int *minParkTime, int *roundedTotal, int *round) {
	if (*minOut < *minIn) {
		*minOut = *minOut + 60;
		*hourOut = *hourOut - 1;
	} else {
		*hourParkTime = *hourOut - *hourIn;
		*minParkTime = *minOut - *minIn;
	}
	
	if(*minParkTime >= 1) {
		*round = *hourParkTime + 1;
	} else {
		*round = *hourParkTime;
	}
	
	*roundedTotal = *round;
}

//Function definition for rate.
void rate(char *vehicle, int *units, float *firstRate, float *secondRate) {
	switch(*vehicle) {
		case 'c': case 'C': *units = 3; *firstRate = firstCarRate; break;
		case 't': case 'T': *units = 1; *firstRate = firstTruckRate; *secondRate = secondTruckRate; break;
		case 'b': case 'B': *units = 2; *firstRate = firstBusRate; *secondRate = secondBusRate; break;
		default: std::cout << "Enter a valid vehicle type. ";
	}
}

//Function definition for charge.
void charge(int *roundedTotal, int *units, float *firstRate, float *secondRate, float *totalCharge) {
	if(*roundedTotal <= *units) {
		*totalCharge = *roundedTotal * *firstRate;
	} else {
		*totalCharge = (*roundedTotal - *units) * *secondRate + *units * *firstRate;
	}
}

//Function definition for print Bill.
void printBill(char *vehicle, int *hourIn, int *minIn, int *hourOut, int *minOut, int *hourParkTime, int *minParkTime, int *roundedTotal, float *totalCharge) {
	std::cout << "Vehicle Type:    " << *vehicle << "\n";
	std::cout << "Time In:         " << *hourIn << ":" << *minIn << "\n";
	std::cout << "Time Out:        " << *hourOut << ":" << *minOut << "\n";
	std::cout << "Total Park Time: " << *roundedTotal << "\n";
	std::cout << "Total Charge:    " << *totalCharge << "\n";
	return;
}

//start main
int main(void) {
	char vehicle; 
	int units, hourIn, minIn, hourOut, minOut, hourParkTime, minParkTime, roundedTotal, round; 
	float firstRate, secondRate, totalCharge;
	
	getInfo(&vehicle, &hourIn, &minIn, &hourOut, &minOut);
	time(&hourIn, &minIn, &hourOut, &minOut, &hourParkTime, &minParkTime, &roundedTotal, &round);
	rate(&vehicle, &units, &firstRate, &secondRate);
	charge(&roundedTotal, &units, &firstRate, &secondRate, &totalCharge);
	printBill(&vehicle, &hourIn, &minIn, &hourOut, &minOut, &hourParkTime, &minParkTime, &roundedTotal, &totalCharge);
	return 0;
} //end of main. 


This code compiles, but gives weird answers. You might need to fix your calculations.
Thanks guys for the support and help. Will work on it a little more and see if i can get it running now. Will let ya know how it goes! Just got out of the hospital so back to what i like lol
Run-Time Check Failure #2 - Stack around the variable 'vehicle' was corrupted.
Okay so I am having no success it getting this error to leave and don't understand or maybe just not seeing it, I thought it had to do with pointers and too much info assigned to variable but I don't see the issue with mine. Help?
Topic archived. No new replies allowed.