0

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 by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by __avd
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;
             }
0

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 by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

0

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 by Nick Evan: Fixed formatting

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.