i've been been trying to decipher what is wrong with this code for some time, help would be apreciated. It is an application in visual studio 2008 with c#, when a user puts in a number, the application checks the number to make sure it is a number, then if it a valid number, then displays the correct grade according to the preset.

private void button1_Click(object sender, EventArgs e)
        {
            int Num = 0;

            if (int.TryParse(lblLetGrade.Text, out Num) == false)
            {
                MessageBox.Show("Input must be a number");
                //return
            }
            if (Num < 0 || Num > 100)
            {
            } MessageBox.Show("Number not valid");
            //return;

            if (Num >= 88 && Num <= 100)
            {
                lblLetGrade.Text = "A";
            }
            else if (Num >= 80 && Num <= 87)
            {
                lblLetGrade.Text = "B";
            }
            else if (Num >= 67 && Num <= 79)
            {
                lblLetGrade.Text = "C";
            }
            else if (Num >= 60 && Num <= 67)
            {
                lblLetGrade.Text = "D";
            }
            else (Num <= 59);
            {
                lblLetGrade.Text = "F";
            }

help please.

thanks guys!

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

if (int.TryParse(lblLetGrade.Text, out Num) == false)
            {
                MessageBox.Show("Input must be a number");
                return;
            }
            if (Num < 0 || Num > 100)
            {
             MessageBox.Show("Number not valid");
             return;
             }

Just to emphasis, this is the part i seem to be stuck on ...

if (int.TryParse(lblLetGrade.Text, out Num) == false)
            {
                MessageBox.Show("Input must be a number");
                return;
            }

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

For easy readability, always wrap programming code within posts in CODE

What is the content of clblLetGrade.Text. It should be a textbox.

if(int.TryParse(textBox1.Text, out Num) == false)
  {
   MessageBox.Show("Input must be a number");
   return;
  }

Edited 3 Years Ago by Nick Evan: Fixed formatting

You're welcome. I'm glad you got it working please mark this thread as solved if you have found an answer to your question and good luck!

This question has already been answered. Start a new discussion instead.