I have an assignment to calculate the *parkingFee*, I'm having a hard time figuring out how to get this code to repeat after a invalid number (greater than 24 or less than 1) has been entered.
The parking fee in a parking station is calculated on whole number of hours multiplied by the hourly rate of $2.50. A program is required to input and validate the hours to be between 1-24 inclusive. Calculate the parking fee given there is a maximum parking fee of $20.00. Output the hours parked and the parking fee (formatted to 2 decimal places)."
Below you'll find the code that I'm having trouble with. Any help would be greatly appreciated.
- namespace _3PRB_Assignment_Part_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- /* Ryley Copeman
- * 29/08/2018
- * Assignment parkingFee2*/
- /* PSEUDOCODE */
- /* HOURLY_RATE=2.5
- * INPUT parkTime
- * parkFee = HOURLY_RATE * hours
- * OUTPUT parkFee */
- decimal parkTime; // input - time in hour eg 1.5 for 1 and a half hours
- const decimal HOURLY_RATE = 2.50m; // HOURLY_RATE * INPUT parkTime = parkFee
- const decimal MAX_FEE = 20.00m; // MAX_FEE is set as a payment cap and ignores any extra charges incurred over 8 hours
- decimal parkFee;
- Console.WriteLine("ParkingFee1 program developed by: Ryley Copeman");
- Console.WriteLine("Please enter your total time parked in hours: Eg 1.5 or 3.0");
- parkTime = decimal.Parse(Console.ReadLine());
- if (parkTime > 8)
- {
- Console.Write("Total fee is $" + MAX_FEE);
- }
- else
- {
- parkFee = Math.Ceiling(parkTime) * HOURLY_RATE;
- Console.Write("Parking Fee = $" + parkFee);
- }
- while(parkTime < 0 || parkTime > 24) // validate...
- //while (parkTime <= 0) )
- {
- Console.WriteLine("Error – Park Time out of range");
- Console.WriteLine("Enter - Park Time between 0 and 24 (HOURS):");
- parkTime = int.Parse(Console.ReadLine());
- }
- }
- }
- }

Rafnas T PPosted Aug 29, 2018, 12:33 AM
Rafnas T PPosted Aug 29, 2018, 12:50 AM