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 doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make
I'm doing an exercise and where I need to create a simple dating agency
I have a generated application where one part is an exercise where the user
I'm doing an exercise over loops and have a doubt. I have an array
I am doing some exercise from a book and have some problems with the
I was doing this as a personal exercise and wanted to make sure I
I'm doing an exercise. The goal is to make a program in C to
I am doing exercise 26 in learn python the hard way and have been
I'm doing some exercise to understand Java and Swing API. Why do I have
I am doing a book exercise regarding the Ackermann function. I have one question

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.