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)
- {
-
-
-
-
-
-
-
-
-
-
-
- decimal parkTime;
- const decimal HOURLY_RATE = 2.50m;
- const decimal MAX_FEE = 20.00m;
- 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)
-
- {
- Console.WriteLine("Error – Park Time out of range");
- Console.WriteLine("Enter - Park Time between 0 and 24 (HOURS):");
- parkTime = int.Parse(Console.ReadLine());
-
- }
-
- }
- }
- }