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!

Recommended Answers

All 5 Replies

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;
            }

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;
  }

thanks! It now works!

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.