Hello,
im doing an exercise where i have to make a parking lot application. The objectives are: Create a form with a numericUpDown control for choosingthe amount of time a vehicle was parked. Add option buttons to show if the vehicle is a car or truck. Clearly label each box and button. Add a label or text box to show the amount to pay.
Also, i have to set some limits. Cars shouldn't pay more than $38.00 for 24 hours, and trucks no more than $44.50 for 24 hours.
The only problem i find is that i cannot set these limits. It gives an error: Use of unassigned local variable 'result' .
Check the commented /// code.
Any help much appreciated. It's not a schoolwork project, i'm just learning c# by myself and doing some exercises.
Here's the code:
private void calculate_Click(object sender, EventArgs e)
{
double carhours = 3;
double truckhours = 3.50;
double carFirsthour = 5;
double truckFirsthour = 6;
int hrs = (int)numericUpDown.Value;
double result;
int maxCarFee = 38;
if (numericUpDown.Value < 1)
{
MessageBox.Show("NO WAY");
return;
}
if (carButton.Checked == true && (numericUpDown.Value == 1))
{
result = (hrs * carFirsthour);
fee.Text = "$" + result;
}
if (carButton.Checked == true && (numericUpDown.Value > 1))
{
result = ((hrs - 1) * carhours + carFirsthour);
fee.Text = "$" + result;
}
if (truckButton.Checked == true && (numericUpDown.Value == 1))
{
result = (hrs * truckFirsthour);
fee.Text = "$" + result;
}
if (truckButton.Checked == true && (numericUpDown.Value > 1))
{
result = ((hrs - 1) * truckhours + truckFirsthour);
fee.Text = "$" + result;
}
/// limits
///if (carButton.Checked == true && (numericUpDown.Value < 24) && (result > maxCarFee))
///{
/// fee.Text = "$" + maxCarFee;
///}
}