I've just started my .Net courses and this is the exercise they made us do at the lab, pretty simple stuff. It worked well at the lab but now that I'm home to retest it, the if condition inside foreach is not working properly. The system is bypassing it automatically for some reason and jumps to first IF outside foreach.
Where am I going wrong with this? Is it that the values are too big "> 1000" ?
Please help me understand what's going on.
private void button1_Click(object sender, EventArgs e)
{
// Adds objects in the ArrayList
f.Clear();
f.Add(textBox1.Text);
f.Add(textBox2.Text);
f.Add(textBox3.Text);
f.Add(textBox4.Text);
f.Add(textBox5.Text);
int result = 0;
// foreach loop into the ArrayList
foreach (object item in f)
{
if (int.Parse(item.ToString()) > 1000)
{
MessageBox.Show("Result Too Big. Terminating!");
break;
}
result += int.Parse(item.ToString());
}
if (result > 80)
{
MessageBox.Show("Excellent, your score is " + result.ToString());
}
else if (result > 60)
{
MessageBox.Show("Good, your score is " + result.ToString());
}
}