# Help with problem in c++ class

#### Asylum

Our teacher gave us some problems to work for class but I dont see anywhere in the book that explains these.
Im sure it is something simple that im overlooking because im good in math.
Could someone show me how to work these.

Following the pseudocode below, what is the value of X if Y = 10?

X=0
If Y > 10 then
X=5
Else
If Y < 20 then
X=7
Else
X=9

#### Asylum

Ok I think I see it already.

X= 7 correct?

#### Vinska

Yes, You are correct. Also, the last branch will never trigger no matter what is the value of Y.

And to finding an answer: if You can't figure out the end result by reading a description/pseudocode/whatever, but can see/understand the algorithm, just write a small test program and simply get the result

#### MrSeanKon

##### New Member
X=5 for all Y values greater than 10.
For values less than 10 e.g. Y=8, Y=9, Y=9.999999999 (not exactly Y=10) X is always 9.
10 value for Y is a "critical" value where the second if/else conditional works.

I don't even get it why you asked?

#### 3870x2

I don't even get it why you asked?
He didn't understand it at first. I thought it was pretty easy. I am sure there was something very specific he wasn't understanding.

#### W1zzard

Staff member
much more readable once you indent it

Code:
``````X=0
If Y > 10 then
X=5
Else
If Y < 20 then
X=7
Else
X=9``````
when using a language that uses closing blocks for if it will be even more readable
Code:
``````X=0
If Y > 10 then
X=5
Else
If Y < 20 then
X=7
Else
X=9
Endif
Endif``````

#### Drone

X=0
If Y > 10 then
X=5
Else
If Y < 20 then
X=7
Else
X=9
It makes no sense at all, especially the first else.

Else means that Y<10 and "if Y<20" is redundant. Because if Y<10 then of course Y<20, that part is captain obvious.

#### Vinska

@Drone

Uhm, it's not Y<10 and Y<20
it's Y>10 and Y<20

Yet, the last else is redundant, 'cause it will never trigger (as I said in my 1st reply )

#### Vinska

@Drone

> No, it's y<10. They wrote:
If Y > 10 then
X=5
Uhm, squeeze me, but aren't You contradicting Yourself?

#### Drone

No need to play word games here. Else means that y is less or equal 10. Period.

#### Vinska

Okay, I won't be playing word games.

Graphical representation:

Edit: OK, now I see Your point. That thing is quite obvious when looking at that "code".
Yet, you wrote it very ambiguously. Ambiguously enough to confuse me into thinking You were trying to say a completely different thing. If You would be less ambiguous next time, I would be grateful. Thank You!

Last edited:

#### 3870x2

Our teacher gave us some problems to work for class but I dont see anywhere in the book that explains these.
Im sure it is something simple that im overlooking because im good in math.
Could someone show me how to work these.

Following the pseudocode below, what is the value of X if Y = 10?

X=0
If Y > 10 then
X=5
Else
If Y < 20 then
X=7
Else
X=9
Would look a lot easier if:

X = 0;
if (Y > 10) then x = 5;
elseif ( Y < 20 ) then X = 7;
else x = 9;
end if

Sometimes pseudocode is just more confusing.