• We've upgraded our forums. Please post any issues/requests in this thread.

Help with problem in c++ class

Joined
Jul 18, 2008
Messages
2,866
Likes
697
Location
South Carolina
System Name KILLER
Processor Intel Core i7 4770K
Motherboard MSI Z87 G45 Gaming
Cooling Water Cooling
Memory 2x4GB Gskill 2400mhz
Video Card(s) EVGA GTX 780TI
Storage SSD Kingston 240GB
Display(s) 24" Asus 144hz
Case Cooler Master HAF
Audio Device(s) X-Fi Platinum
Power Supply Antec 1200 Watt Modular
Software Windows 7 64 Bit
Benchmark Scores 3DMark Vantage 51342
#1
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.
Thanks in advance.


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
 
Joined
Jul 18, 2008
Messages
2,866
Likes
697
Location
South Carolina
System Name KILLER
Processor Intel Core i7 4770K
Motherboard MSI Z87 G45 Gaming
Cooling Water Cooling
Memory 2x4GB Gskill 2400mhz
Video Card(s) EVGA GTX 780TI
Storage SSD Kingston 240GB
Display(s) 24" Asus 144hz
Case Cooler Master HAF
Audio Device(s) X-Fi Platinum
Power Supply Antec 1200 Watt Modular
Software Windows 7 64 Bit
Benchmark Scores 3DMark Vantage 51342
#2
Ok I think I see it already.

X= 7 correct?
 
Joined
Jul 23, 2011
Messages
1,555
Likes
1,459
Location
Kaunas, Lithuania
System Name Eternal WIP ][ HP ProLiant server blade
Processor AMD FX-8320 @ 4.4/4.1 GHz ][ 2x Intel Xeon L5520 @ 2.27GHz
Motherboard Asus Crosshair V Formula-Z ][ -
Cooling Corsair H55 ][ Stock
Memory 2x4GB Kingston HyperX Genesis @ 1866MHz ][ 4x4 GiB Hynix @ 1333 MHz; ECC on
Video Card(s) 2x MSI GeForce GTX 770 DirectCU II OC ][ None
Storage 1TB WD Black + 1.5TB WD Green + 750GB Samsung + 64GB OCZ Agility 4 ][ 3x 1 TB Hitachi
Display(s) Asus VG278H + Asus VH226H ][ None
Case Antec Nine Hundred ][ it's a server blade, lol
Audio Device(s) Supreme FX II (Integrated); Using optical S/PDIF output ][ none
Power Supply Corsair AX1200i ][ [stock]
Software Gentoo Linux ][ Linux Mint 16
Benchmark Scores 65970 BogoMIPS. Ha. Ha. Ha. >=|
#3
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 :p
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267
Likes
73
Location
Athens in love with Anna :)
#4
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.
 
Joined
Dec 2, 2009
Messages
3,257
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#5
I don't even get it why you asked?
 
Joined
Feb 26, 2008
Messages
4,870
Likes
681
Location
Joplin, Mo
System Name Ultrabeast GX2
Processor Intel Core 2 Duo E8500 @ 4.0GHZ 24/7
Motherboard Gigabit P35-DS3L
Cooling Rosewill RX24, Dual Slot Vid, Fan control
Memory 2x1gb 1066mhz@850MHZ DDR2
Video Card(s) 9800GX2 @ 690/1040
Storage 750/250/250/200 all WD 7200
Display(s) 24" DCLCD 2ms 1200p
Case Apevia
Audio Device(s) 7.1 Digital on-board, 5.1 digital hooked up
Power Supply 700W RAIDMAXXX SLI
Software winXP Pro
Benchmark Scores 17749 3DM06
#6
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

Administrator
Staff member
Joined
May 14, 2004
Messages
17,021
Likes
17,869
Processor Core i7-4790K
Memory 16 GB
Video Card(s) GTX 1080
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 7
#7
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
 
Joined
Sep 1, 2010
Messages
5,891
Likes
6,551
#8
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.
 
Joined
Jul 23, 2011
Messages
1,555
Likes
1,459
Location
Kaunas, Lithuania
System Name Eternal WIP ][ HP ProLiant server blade
Processor AMD FX-8320 @ 4.4/4.1 GHz ][ 2x Intel Xeon L5520 @ 2.27GHz
Motherboard Asus Crosshair V Formula-Z ][ -
Cooling Corsair H55 ][ Stock
Memory 2x4GB Kingston HyperX Genesis @ 1866MHz ][ 4x4 GiB Hynix @ 1333 MHz; ECC on
Video Card(s) 2x MSI GeForce GTX 770 DirectCU II OC ][ None
Storage 1TB WD Black + 1.5TB WD Green + 750GB Samsung + 64GB OCZ Agility 4 ][ 3x 1 TB Hitachi
Display(s) Asus VG278H + Asus VH226H ][ None
Case Antec Nine Hundred ][ it's a server blade, lol
Audio Device(s) Supreme FX II (Integrated); Using optical S/PDIF output ][ none
Power Supply Corsair AX1200i ][ [stock]
Software Gentoo Linux ][ Linux Mint 16
Benchmark Scores 65970 BogoMIPS. Ha. Ha. Ha. >=|
#9
@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 ;) )
 
Joined
Jul 23, 2011
Messages
1,555
Likes
1,459
Location
Kaunas, Lithuania
System Name Eternal WIP ][ HP ProLiant server blade
Processor AMD FX-8320 @ 4.4/4.1 GHz ][ 2x Intel Xeon L5520 @ 2.27GHz
Motherboard Asus Crosshair V Formula-Z ][ -
Cooling Corsair H55 ][ Stock
Memory 2x4GB Kingston HyperX Genesis @ 1866MHz ][ 4x4 GiB Hynix @ 1333 MHz; ECC on
Video Card(s) 2x MSI GeForce GTX 770 DirectCU II OC ][ None
Storage 1TB WD Black + 1.5TB WD Green + 750GB Samsung + 64GB OCZ Agility 4 ][ 3x 1 TB Hitachi
Display(s) Asus VG278H + Asus VH226H ][ None
Case Antec Nine Hundred ][ it's a server blade, lol
Audio Device(s) Supreme FX II (Integrated); Using optical S/PDIF output ][ none
Power Supply Corsair AX1200i ][ [stock]
Software Gentoo Linux ][ Linux Mint 16
Benchmark Scores 65970 BogoMIPS. Ha. Ha. Ha. >=|
#11
@Drone

> No, it's y<10. They wrote:
If Y > 10 then
X=5
Uhm, squeeze me, but aren't You contradicting Yourself?
 
Joined
Jul 23, 2011
Messages
1,555
Likes
1,459
Location
Kaunas, Lithuania
System Name Eternal WIP ][ HP ProLiant server blade
Processor AMD FX-8320 @ 4.4/4.1 GHz ][ 2x Intel Xeon L5520 @ 2.27GHz
Motherboard Asus Crosshair V Formula-Z ][ -
Cooling Corsair H55 ][ Stock
Memory 2x4GB Kingston HyperX Genesis @ 1866MHz ][ 4x4 GiB Hynix @ 1333 MHz; ECC on
Video Card(s) 2x MSI GeForce GTX 770 DirectCU II OC ][ None
Storage 1TB WD Black + 1.5TB WD Green + 750GB Samsung + 64GB OCZ Agility 4 ][ 3x 1 TB Hitachi
Display(s) Asus VG278H + Asus VH226H ][ None
Case Antec Nine Hundred ][ it's a server blade, lol
Audio Device(s) Supreme FX II (Integrated); Using optical S/PDIF output ][ none
Power Supply Corsair AX1200i ][ [stock]
Software Gentoo Linux ][ Linux Mint 16
Benchmark Scores 65970 BogoMIPS. Ha. Ha. Ha. >=|
#13
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:
Joined
Feb 26, 2008
Messages
4,870
Likes
681
Location
Joplin, Mo
System Name Ultrabeast GX2
Processor Intel Core 2 Duo E8500 @ 4.0GHZ 24/7
Motherboard Gigabit P35-DS3L
Cooling Rosewill RX24, Dual Slot Vid, Fan control
Memory 2x1gb 1066mhz@850MHZ DDR2
Video Card(s) 9800GX2 @ 690/1040
Storage 750/250/250/200 all WD 7200
Display(s) 24" DCLCD 2ms 1200p
Case Apevia
Audio Device(s) 7.1 Digital on-board, 5.1 digital hooked up
Power Supply 700W RAIDMAXXX SLI
Software winXP Pro
Benchmark Scores 17749 3DM06
#14
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.
Thanks in advance.


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.