bullet-401 July 16, 2004 Share bullet-401 Member July 16, 2004 This should be a lot of fun. NOFX, great idea. RULES: Code should have a number or word answer to it. This is on a trust system too. No using code programs. One that answers the code correct gets to make up another. There is a BB code thing.. use it. NOFX's code while (x <=10, x++); { i = i+x; } print i; Answer was 55. My new one. int y,x; int n=0; for (x=0;x<=10;x++){ for (y=10;y>0;y--){ x++; if ((x>5)&&(y>1)) n++; } } What is n? Link to comment Share on other sites More sharing options...
PHYZER23 July 16, 2004 Share PHYZER23 Member July 16, 2004 if u asked me this like 8 months ago i would know but since summer has come along i forget everything i learned during the skool year Link to comment Share on other sites More sharing options...
bullet-401 July 16, 2004 Author Share bullet-401 Member July 16, 2004 yeah it took me a while to figure out a good one Link to comment Share on other sites More sharing options...
dwEEziL July 16, 2004 Share dwEEziL Member July 16, 2004 Why confine it to just c++? Link to comment Share on other sites More sharing options...
bullet-401 July 16, 2004 Author Share bullet-401 Member July 16, 2004 FINE Link to comment Share on other sites More sharing options...
TheBugs July 16, 2004 Share TheBugs Member July 16, 2004 /me look in and realizes hes completly lost ** looks around ** /me walks out Link to comment Share on other sites More sharing options...
NOFX July 16, 2004 Share NOFX Member July 16, 2004 (edited) I have never programmed in C++. I have done a little bit of C, Syntax doesnt really matter, its all the same It looks like Java to me. Ok, I rethought this, im confused because you have two x's the varible x that is incremented on the inside loop and the outter for loop has x as a counter. perhaps make these two separate varibles? if we had int y,x,i;int n=0; for (i=0;i<=10;i++){ for (y=10;y>0;y--){ x++; if ((x>5)&&(y>1)) n++; } } I think the answer would be..... Edited July 16, 2004 by NOFX Link to comment Share on other sites More sharing options...
NOFX July 16, 2004 Share NOFX Member July 16, 2004 (edited) everytime the inner loop is completed n++ is called 4 times. If the outer loop is ran 11 times(because x is initally 0 so it would really execute the loop 11 times), the answer would be 44. How about that? Edited July 16, 2004 by NOFX Link to comment Share on other sites More sharing options...
appalachian_fox July 16, 2004 Share appalachian_fox Member July 16, 2004 Would the loop execute 11 times? Look carefully in the y part. Link to comment Share on other sites More sharing options...
NOFX July 16, 2004 Share NOFX Member July 16, 2004 (edited) the outter loop does. for (x=0;x<=10;x++); The inner loop will execute 10 times for each pass of the outer loop. Edited July 16, 2004 by NOFX Link to comment Share on other sites More sharing options...
Xterminator July 16, 2004 Share Xterminator Member July 16, 2004 (edited) yeah guess who wont be taking part in this game....me Edited July 16, 2004 by Xterminator Link to comment Share on other sites More sharing options...
appalachian_fox July 19, 2004 Share appalachian_fox Member July 19, 2004 But NoFX, look at the Y-loop. It increments X. Link to comment Share on other sites More sharing options...
NOFX July 19, 2004 Share NOFX Member July 19, 2004 But NoFX, look at the Y-loop. It increments X. yea thats what confuses me, thats why I set up three varibles instead of 2. so if we leave it at 2 we have. int y,x;int n=0; for (x=0;x<=10;x++){ for (y=10;y>0;y--){ x++; if ((x>5)&&(y>1)) n++; } } What is n? K with this, I think we have x=10, n=4 after the first outer loop. x<=10 so we can do the outer loop once again. This time the inner loop will go run but never increment n, because x will always be greater than 5. so the answer is 4? and the outer loop is useless? where u at bullet? Link to comment Share on other sites More sharing options...
bullet-401 July 19, 2004 Author Share bullet-401 Member July 19, 2004 Lol forgot about this topic. I went through it and got this. X Y N 0 10 0 1 9 1 2 8 2 3 7 3 5 6 4 6 5 5 7 4 8 3 9 2 10 1 11 0 I think thats right. Not really sure since I made it up on the fly. So I got X=11 Y=0 N=5. Not sure if thats right though. Link to comment Share on other sites More sharing options...
NOFX July 19, 2004 Share NOFX Member July 19, 2004 Lol forgot about this topic. I went through it and got this. X Y N 0 10 0 1 9 1 2 8 2 3 7 3 5 6 4 6 5 5 7 4 8 3 9 2 10 1 11 0 I think thats right. Not really sure since I made it up on the fly. So I got X=11 Y=0 N=5. Not sure if thats right though. I dont think that is right, because your incrementing N on the second pass when x=1 & y=9. Impossible if n++ only when x>5 & y>1 Link to comment Share on other sites More sharing options...
bullet-401 July 19, 2004 Author Share bullet-401 Member July 19, 2004 Oh sorry for the confusion. I just put down each time it changes. Now I fixed it so each row is one pass. int y,x; int n=0; for (x=0;x<=10;x++){ for (y=10;y>0;y--){ x++; if ((x>5)&&(y>1)) n++; } } X Y N 0 10 0 <--Starts both for statements 1 9 0 <--\/Cycles down till y gets to 0\/ 2 8 0 3 7 0 5 6 0 6 5 1 7 4 2 8 3 3 9 2 4 10 1 5 11 0 5 <-- Exits 2nd for statement 12 0 5 <---final after the initial for statement is done. Link to comment Share on other sites More sharing options...
appalachian_fox July 19, 2004 Share appalachian_fox Member July 19, 2004 I had 4...Anybody check this code? Maybe someone with a few minutes can change it to Basic code and run it in VBA in Word or something? Link to comment Share on other sites More sharing options...
Playaa July 19, 2004 Share Playaa Member July 19, 2004 x=0 y=10 n=0 x=1 y=9 n=0 x=2 y=8 n=0 x=3 y=7 n=0 x=4 y=6 n=0 x=5 y=5 n=0 x=6 y=5 n=1 x=6 y=4 n=1 x=7 y=4 n=2 x=7 y=3 n=2 x=8 y=3 n=3 x=8 y=2 n=3 x=9 y=2 n=4 x=9 y=1 n=4 x=10 y=0 n=4 x=11 y=0 n=4 Link to comment Share on other sites More sharing options...
bullet-401 July 19, 2004 Author Share bullet-401 Member July 19, 2004 Well I converted it to VB but I don't know how to output the answers. Dim n Dim x Dim y n = 0 For x = 0 To 10 For y = 10 To 1 x = x + 1 If x > 5 And y > 1 Then n = n + 1 End If Next y Next x Link to comment Share on other sites More sharing options...
NOFX July 19, 2004 Share NOFX Member July 19, 2004 heh yea I had 4 until I changed his code to where the outer loop didnt use x . Someone else post some code, whenever I get some time ill reinstall jsdk, im gonna be needing it for Java III in the fall, will be my third attempt at the class. you could just look up the vbscript syntax, type it in notepad and throw a vbs extension on it and it should work fine. Link to comment Share on other sites More sharing options...
Playaa July 20, 2004 Share Playaa Member July 20, 2004 it will never cease to amaze me how often a c-based programmer can't figure out how to do things in VB...I mean seriously...it's SUPPOSED to be a less complicated language here Link to comment Share on other sites More sharing options...
appalachian_fox July 20, 2004 Share appalachian_fox Member July 20, 2004 Bullet, try MsgBox (n). Link to comment Share on other sites More sharing options...
bullet-401 July 20, 2004 Author Share bullet-401 Member July 20, 2004 Ok I ran this Sub test() Dim N, X, Y As Integer N = 0 For X = 0 To 10 For Y = 10 To 1 X = X + 1 If X > 5 And Y > 1 Then N = N + 1 End If Next Y Next X MsgBox (N) MsgBox (X) MsgBox (Y) End Sub I got N=0 X=11 Y=10. SO, my syntax is wrong in VB. Can anyone look at this and fix it? Link to comment Share on other sites More sharing options...
bullet-401 July 20, 2004 Author Share bullet-401 Member July 20, 2004 it will never cease to amaze me how often a c-based programmer can't figure out how to do things in VB...I mean seriously...it's SUPPOSED to be a less complicated language here Yeash. It is very confusing. I never took VB and I probly never will. :sigh: The basics of it is very easy but I still don't get the logic of it. Link to comment Share on other sites More sharing options...
appalachian_fox July 20, 2004 Share appalachian_fox Member July 20, 2004 Yeah, this is really obscure... FOR Y = 10 TO 1 STEP -1 Otherwise BASIC will always assume you want to increment by 1. So, Y = 10, then next loop, Y = 11, which exceeds the bounds....I'm pretty sure it always runs through the loop at least once. Add that STEP -1 though. It's like the y-- operator. Link to comment Share on other sites More sharing options...
Recommended Posts