• Create Account

### #Actualbrx

Posted 16 August 2012 - 07:06 AM

The problem is that the if statements are all executed in exactly the order you stated them. So when, for example, you enter 40, the condition if (age >= 17) will be executed and return true. Therefore all the other if statements are actually dead code (i.e. unreachable code). What you need to do is put both conditions age >= 17 and age < 26 into one statement using the '&&;' operator:
else if (age >= 17 && age <26) {
MessageBox.Show("Fame beckons!");
}

This way the "Fame beckons!" message box will only appear when the age is between 17 and 26. Same applies for the "There's still time!" case.

EDIT: Damn, editing messes up the '&' showing up correctly.

### #3brx

Posted 16 August 2012 - 07:05 AM

The problem is that the if statements are all executed in exactly the order you stated them. So when, for example, you enter 40, the condition if (age >= 17) will be executed and return true. Therefore all the other if statements are actually dead code (i.e. unreachable code). What you need to do is put both conditions age >= 17 and age < 26 into one statement using the '&amp;amp;&amp;amp;' operator:
else if (age >= 17 && age <26) {
MessageBox.Show("Fame beckons!");
}

This way the "Fame beckons!" message box will only appear when the age is between 17 and 26. Same applies for the "There's still time!" case.

### #2brx

Posted 16 August 2012 - 07:04 AM

The problem is that the if statements are all executed in exactly the order you stated them. So when, for example, you enter 40, the condition if (age >= 17) will be executed and return true. Therefore all the other if statements are actually dead code (i.e. unreachable code). What you need to do is put both conditions age >= 17 and age < 26 into one statement using the '&amp;&amp;' operator:
else if (age >= 17 &amp;&amp; age <26) {
MessageBox.Show("Fame beckons!");
}

This way the "Fame beckons!" message box will only appear when the age is between 17 and 26. Same applies for the "There's still time!" case.

### #1brx

Posted 16 August 2012 - 07:03 AM

The problem is that the if statements are all executed in exactly the order you stated them. So when, for example, you enter 40, the condition if (age >= 17) will be executed and return true. Therefore all the other if statements are actually dead code (i.e. unreachable code). What you need to do is put both conditions age >= 17 and age < 26 into one statement using the '&&' operator:
else if (age >= 17 && age <26) {
MessageBox.Show("Fame beckons!");
}

This way the "Fame beckons!" message box will only appear when the age is between 17 and 26.

PARTNERS