Web Analytics Made Easy -
StatCounter C-Sharp coding question - CodingForum

Announcement

Collapse
No announcement yet.

C-Sharp coding question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C-Sharp coding question

    I have a question, below is a portion of my code for a school assignment. I have already turned in the code and it works, but I was thinking that there was an easier way to get the program to act the same way with some simpler code. Any ideas?

    private void btnCategorize_Click(object sender, EventArgs e)
    {
    /* This is a GUI program that tells the user what
    * category the hurricane falls into base off of
    * user input of windspeed
    * created by: Jeffery Rice
    * September 14, 2016
    * Chapter 4 Excercise 5b */

    const int CATEGORY_ONE = 74;
    const int CATEGORY_TWO = 96;
    const int CATEGORY_THREE = 111;
    const int CATEGORY_FOUR = 130;
    const int CATEGORY_FIVE = 157;
    int windSpeed;

    windSpeed = Convert.ToInt32(txtWindSpeed.Text);
    if (windSpeed >= CATEGORY_ONE && windSpeed < CATEGORY_TWO)
    {
    outputLabel.Text = "This is a category 1 hurricane";
    }
    else
    {
    if (windSpeed >= CATEGORY_TWO && windSpeed < CATEGORY_THREE)
    {
    outputLabel.Text = "This is a category 2 hurricane";
    }
    else
    {
    if (windSpeed >= CATEGORY_THREE && windSpeed < CATEGORY_FOUR)
    {
    outputLabel.Text = "This is a category 3 hurricane";
    }
    else
    {
    if (windSpeed >= CATEGORY_FOUR && windSpeed < CATEGORY_FIVE)
    {
    outputLabel.Text = "This is a category 4 hurricane";
    }
    else
    {
    if (windSpeed >= CATEGORY_FIVE)
    {
    outputLabel.Text = "This is a category 5 hurricane";
    }
    else
    {
    outputLabel.Text = "This is not a hurricane";
    }

    }
    }
    }
    }

    }
Working...
X