954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

[split Loop counting odd and even numbers

I am also a New Learner, Base on the Request, This Simple Code would detect if a Number is Even or ODD number....

// This is to Detect Odd and Even Number

bool ValidateDegreeValue; // This is to Validate that the User Enter Number Data
        double DegreeValueNum; // This Define the Length of the Number that the User can Enter
        // The below Code will notify the User if the data enter is not Numerical
        ValidateDegreeValue = double.TryParse(txtDegreeValue.Text, out DegreeValueNum);
        if (ValidateDegreeValue == false)
        {
            MessageBox.Show("Enter Valid Temperature Value", "Input Error");
            txtDegreeValue.Focus();
            return;
        }  

   if (DegreeValueNum % 2 == 0)
        {
            txtNumClass.Text = DegreeValueNum.ToString() + " Is an Even Number";
        }
        else
        {
            txtNumClass.Text = DegreeValueNum.ToString() + " Is an Odd Number";
        }
jnmisa
Newbie Poster
15 posts since Nov 2011
Reputation Points: 10
Solved Threads: 1
 

And your question is?

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

WaltP, I think this is just a code snippet.

jnmisa, you can remove the use of the bool "ValidateDegreeValue" and put the TryParse iside the "if" statement if you want.

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

Obviously. But why?

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

I don't have a Question concern that... I put it there that it might help someone like me

jnmisa
Newbie Poster
15 posts since Nov 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You