Can you tell me what is wrong with this IF statement??
I think I mix something with operators.
namespace exercise1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int age;
age = int.Parse(textBox1.Text);
if (age < 17)
{
MessageBox.Show("You're still a youngster.");
}
if (age <= 25)
{
MessageBox.Show("Fame beckons!");
}
if (age <= 40)
{
MessageBox.Show("There's still time.");
}
if (age > 40)
{
MessageBox.Show("Oh dear, you've probably missed it!");
}
}
}
}
Thanks for help!!!
Loading
Sam HobbsPosted Nov 11, 2011, 1:18 PM
Sam HobbsPosted Nov 11, 2011, 2:03 PM
Josip PavicPosted Nov 11, 2011, 7:58 AM
Mayur GujrathiPosted Nov 11, 2011, 7:44 AM
your code seems correct but due to your code logic
if suppose a no is less than 25 then it executes respective code
then control comes down and will check less than 40 which also becomes true and again executes code in that block
either do as suggested satish or get out of block after displaying massagebox
Josip PavicPosted Nov 11, 2011, 7:43 AM
Satish BhatPosted Nov 11, 2011, 7:37 AM
Josip PavicPosted Nov 11, 2011, 7:34 AM