TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ryley C
NA
4
618
How to repeat code after invalid data is entered
Aug 29 2018 12:20 AM
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());
}
}
}
}
Reply
Answers (
2
)
How to enumerate BlockingCollection not destroying elements?
how to delete an specific row/multiple array in datagridview