...

View Full Version : Working With If...Then Statements

FIR93
10-16-2012, 08:40 PM
I'm doing a homework assignment where I have to look at the code created by my teacher and write what the answer would be using the information given.

So x starts at 7
y starts at 12

Using the info below.

First she declared her variables and her statement looks like this:

If x <= 7 Or y > 11 Then
If x > 2 Or y > 9 Then
y = 4 * y + x
Else
y = x - 8
If x + y > 14 Then
x = x - 7
End If
End If

So looking at this the first If...Then statement is true then I go to the second one which is 'If x > 2 Or y > 9 Then'
and if that one is true as well I plug in my numbers to solve for 'y'. But do I use the same equation to solve for x as well?

Thanks for all help given :)

10-16-2012, 08:53 PM
if 7 <= 7 OR 12 > 11 THEN // they both are
if 7 > 2 OR 12 > 9 THEN // they both are
y=4 * 12 + 7 //55
ELSE
y = 12 - 8 //4
IF 7 + 4 > 14 THEN // it isn't
x = 7-7

FIR93
10-17-2012, 01:51 AM
So for thee final answer y =4 and x=0 ?

Fou-Lu
10-17-2012, 02:50 AM
There is no way to tell with what you have here. Since you'll never enter that else statement, and there is mismatched end if with the if. . .then calls, there are. . . looks like 3 possible outcomes with the above algorithm. My personal answer with that above block is a compilation error.

Since the else can never be executed in the above code no matter how its written, y will always be 55, and x will be either 0 or 7.