Need your inputs please

Pages: 123
closed account (oy0Gy60M)
I have changed and adapted per your advice but still the TotalCharges are not correct.

Can you give us some formula how TotalCharges is calculated?
Beginner2016:

You are struggling with logic because you are essentially trying to do the same tariff calculation for three different types of vehicle. This is repetitive and unnecessary.

Rather than having separate variables for each type of vehicle, why don't you define the single tariff variables
MinFee, MinTime, HourlyRate
and set these (appropriately for each type of vehicle) in the same switch block as you set vehicleText. Then your entire tariff calculation amounts to
1
2
   TotalCharges = MinFee; 
   if ( HourParkTime > MinTime ) TotalCharges += ( HourParkTime - MinTime ) * HourlyRate;


There is no need for a variable TotalParkTime (which you have repeatedly been using undefined).

Just a suggestion!
Last edited on
TotalCharges are not correct.

Can you be more specific about what is not correct.
What inputs are you supplying?
What outputs are you getting?
What outputs are you expecting?

Your code looks better, although it still has some problems. All of which I have mentioned before.

- Your assignment states you must use function calls. You have no function calls in your program. I gave you an example function (get_int) that you can use to gracefully accept only valid hours and minutes.

Lines 14-16,20-22: These should be const.

Line 52: If the user enters an invalid character, you terminate the program. It would be better to have a loop that prompt the user to reenter the value until a valid value is entered.

Line 67-69: You use HourIn,HourOut,MinIn,MinOut before you've checked that they're valid.

Lines 71-75: If any of the values are invalid, you exit the program. Again, a loop to reprompt the user until they've entered valid values is appropriate here. Or use the get_int() function I provided previously.

Line 74: Your return value makes no sense. Why are you returning a boolean OR of these values?

Line 107: Your cout should be vehicleText.
Last edited on
Topic archived. No new replies allowed.
Pages: 123