c# - How do I check if a number in a textbox is greater than a predefined value -


The item is doing an exercise where I have a purpose to make a parking spot: To create a form, create a form with a numeric updance control. Add option button to show whether the vehicle is a car or truck. Clearly label each box and button. Add a label or text box to show the amount of the payment.

In addition, I have to set some limits that cars should not pay more than $ 38.00 for 24 hours and trucks should not exceed $ 44.50 for 24 hours.

The only problem I get is that I can not set these limits, it gives an error: the use of the assigned local variable 'result'.

Checked out the /// code checked.

Any help is greatly appreciated It is not a school project, I am just learning C # with myself and doing some exercise.

Here is the code:

  Calculate Private Zero (Object Sender, Eventarges e) {Double carhors = 3; Double trucks = 3.50; Double CarFirsthour = 5; Double truck aftihour = 6; Int hours = (int) numeric UPDown.Value; Double results; Int maxCarFee = 38; If (numericUpDown.Value & lt; 1) {MessageBox.Show ("NO WAY"); Return; } If checked (Carbutton == true & amp; amp; (numeric UPDown.Value == 1)) {Result = (hours * CarFirsthour); Fee.Text = "$" + results; } If checked (Carbutton was == true & amp; amp; (UPDown.Value & gt; 1)) (result = (hour -1) * carhours + carFirsthour; Fee.Text = "$" + results; } If (truck button is checked == true & amp; amp; (numeric UPDown.Value == 1)) {result = (hours * truck firsthour); Fee.Text = "$" + results; } If (truckButton.Checked == True & amp; amp; amp; amp; (UPDown.Value & gt; 1)) (Results = ((hour - 1) * truckhours + truckFirsthour); Fee.Text = "$" + results; } /// Series /// if (Carbutton is checked == True & amp; amp; amp; amp; amp; amp ;. (& quot; 24 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp amp; /// {/// fee.Text = "$" + Maximize; ///}}  

Try doing something like this:

< Pre> Calculate Private Zero (Object Sender, EventAgds E) {Double Cahors = 3.0; Double trucks = 3.5; Double CarFirsthour = 5.0; Double truckfasthour = 6.0; Double Maxcaffe = 38.0; Double Maxcuffy = 44.5; Int hours = (int) numeric UPDown.Value; Double results; If (hours & lt; 1) {MessageBox.Show ("No Way"); Return; } If (Carbutton Check) {Results = (HR-1) * Carhoros + Carfurstshore; If (Results> Maxcarfi) {Results = Maxim; }} And {result = (hour -1) * truckhorst + truck fasthur; If (Results> Maxtrackfi) {Results = Maxcrackie; }} Fee.Text = "$" + results; }

However, you do not really clarify what should be, if a car / truck lasts more than 24 hours (or more than 48 hours). You can eliminate more consistent results with something like this:

  Calculate Private Zero (Object Sender, EventAgds E) {Double Hourwise = 3.0; Double first = 5.0; Double max 400 h = 38.0; If (HourlyFee = 3.5; FirstHourFee = 6.0; maximum 24 hours = 44.5;} int hrs = (int) numericUpDown.Value; if (hours & lt; 1) {MessageBox.Show ("No way! "Return"; double result = 0.0; if (hours> = 24) {result = (hour / 24) * maximum 24 hours; hours = pm% 24;} if (hours> 0) {result = Result + FirstHalf + ((hour -1) * hourly EF);} Fee. Text = "$" + Result;}  

Comments