Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 928949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:05:31+00:00 2026-05-15T20:05:31+00:00

im doing an exercise where i have to make a parking lot application. The

  • 0

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;
        ///}
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:05:32+00:00Added an answer on May 15, 2026 at 8:05 pm

    Try something like this:

    private void calculate_Click(object sender, EventArgs e) {
        double carhours = 3.0;
        double truckhours = 3.5;
        double carFirsthour = 5.0;
        double truckFirsthour = 6.0;
        double maxCarFee = 38.0;
        double maxTruckFee = 44.5;
    
        int hrs = (int)numericUpDown.Value;
        double result;
    
        if (hrs < 1) {
            MessageBox.Show("NO WAY");
            return;
        }
    
        if (carButton.Checked) {
            result = (hrs-1) * carhours + carFirsthour;
            if (result > maxCarFee) {
                result = maxCarFee;
            }
        }
        else {
            result = (hrs-1) * truckhours + truckFirsthour;
            if (result > maxTruckFee) {
                result = maxTruckFee;
            }
        }
    
        fee.Text = "$" +  result;
    }
    

    However, you don’t really make it clear what should happen if a car/truck stays for more than 24 hours (or more than 48 hours). You might end up with more consistent results with something like this:

    private void calculate_Click(object sender, EventArgs e) {
        double hourlyFee = 3.0;
        double firstHourFee = 5.0;
        double max24hrFee = 38.0;
    
        if (!carButton.Checked) {
           hourlyFee = 3.5;
           firstHourFee = 6.0;
           max24hrFee = 44.5;
        }
    
        int hrs = (int)numericUpDown.Value;
        if (hrs < 1) {
            MessageBox.Show("NO WAY");
            return;
        }
    
        double result = 0.0;
        if (hrs >= 24) {
           result = (hrs / 24) * max24hrFee;
           hrs = hrs % 24;
        }
    
        if (hrs > 0) {
           result = result + firstHourFee + ((hrs-1) * hourlyFee);
        }
    
        fee.Text = "$" +  result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just doing an exercise where I have a list of files (given as
I am doing exercise on Singpath and I am stuck at this question. This
For an exercise I'm doing, I'm trying to read the contents of a given
I'm doing K&R Exercise 5-4 (p107). Write the function strend(s,t) , which returns 1
I have an Album class and a Track class. Tracks can exist independently of
I'm trying to implement The Game of Life in java, as an exercise to
I am evaluating some web application frameworks out there, and finally, two of the
we have about 1000 free seats for our lectures at our uni, and around
I should define a function overlapping() that takes two lists and returns True if
I'm having some trouble solving the problem below (My thinking on how I might

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.