Tell me I am wrong Beginner2016 but I think you are supposed to add to the starter solution you were given and write the lines of program that extend it to perform the required functions. Until you write those lines that's about it. Maybe it all happens after the 'Press any key to continue ...' but I doubt it. :)
I figured that is caused by the return 0; but I still can can't figure out why it's not giving the expected output. Please help, I am just a new to this.
I did Mickey Boy and it's giving me an error code 4700
1 2
Severity Code Description Project File Line Suppression State
Error C4700 uninitialized local variable 'TotalParkTime' used TRY e:\cosc_1436\try\try\try.cpp 73
Mikey Boy, that's really what I am trying to figure out because this is my initial version before lastchance's fix and this version was not giving error message but was not displaying the TotalCharges and the ParkTime
In the criteria for allotting charges (the 'if' conditions in lines 73, 79, 85 in the full version of code that I posted) you use a variable TotalParkTime which hasn't been set up this point. (Not sure why my compiler didn't pick it up - the CPP shell compiler linked to this site warns you if you look hard enough.) I suspect that you meant HourParkTime in each of these 3 statements.
There is also another fault of these 3 if statements which hasn't been picked up (yet): e.g. the 'C' || 'c'
bit. (I only picked it up because I incurred unreasonable parking charges!)
I think this full if statement should be if ((vehicleType == 'C' || vehicleType == 'c') && (HourParkTime > 3))
with similar corrections to the other two.
Line 10: TotalParkTime is an uninitialized variable (garbage).
Line 70: You calculate TotalParkTime only if it's a car.
Line 72: You make a decision on TotalParkTime, which is garbage if it wasn't a car.
You have similar problems at lines 82-83 and 92-93.
You probably want your code to look something like this:
1 2 3 4 5 6 7 8 9 10 11 12
int TotalParkTime = 0; // INITIALIZE VARIABLES
double TotalCharges = 0.0;
...
if (vehicleType == 'C')
{ TotalParkTime = HourParkTime - 3;
// Note the nested if
if (TotalParkTime > 0)
{ TotalCharges = (TotalParkTime * CarHourlyRate);
}
// else not needed as TotalCharges is already 0.
}
// Similar for Bus and Truck
Line 104: You probably want vehicleText here, not vehicleType.
I just realized that the Totalcharges should equal the Minimum charges depending on each vehicle type and I have made these changes but I am also getting the error 4700 for "TotalCharges" on the last line. Please help. Thank you
Lines 78-79, 92-93, 106-107: You're creating new local instances of these variables. These variables go out of scope (contents lost) at lines 89,103,118 respectively.
Sorry AbstractionAnon, I did not ignore your advice but I think I posted before refreshing and didn't see it. I have changed and adapted per your advice but still the TotalCharges are not correct. Here's what I came up with but I am failing to make it work