Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » General Discussions » General Discussion » OT: C++ Recursion
OT: C++ Recursion [message #192146] Tue, 07 March 2006 20:25 Go to next message
icedog90 is currently offline  icedog90
Messages: 3483
Registered: April 2003
Karma: 0
General (3 Stars)
http://img328.imageshack.us/img328/2981/die3qy.png

Anyone who knows at least the basics of C++, can you help me try to understand this damn awful question? My head hurts like hell by going over and over again trying to figure out why the answer is number 3. First, I was beginning to understand why it was 3, and now (after going over it so many times) my head is so fried I don't even remember how it works. I'm done trying to figure this out, my head hurts a lot and it's just pissing me off.

Remember, the answer is 3 (letter C) but I want to know why.

(This is a review I brought home to get ready for a test)

Thanks.
Re: OT: C++ Recursion [message #192148 is a reply to message #192146] Tue, 07 March 2006 20:42 Go to previous messageGo to next message
Dave Anderson is currently offline  Dave Anderson
Messages: 1953
Registered: December 2004
Location: United States
Karma: 0
General (1 Star)
I don't have any of my C++ programming books anymore, and I forgot what the % operator stands for. If you can tell me that, I may be able to figure it out.

EDIT: Nevermind, I remember now. the % operator is a modulus. Example: int rem = 4 % 3;

Of course you probobly already know that...lol. I will further try to figure this out.

What are your thoughts on this so far?


David Anderson
Founder, Software Consultant
DCOM Productions
Microsoft Partner (MSP)

[Updated on: Tue, 07 March 2006 20:52]

Report message to a moderator

Re: OT: C++ Recursion [message #192153 is a reply to message #192146] Tue, 07 March 2006 21:28 Go to previous messageGo to next message
Oblivion165 is currently offline  Oblivion165
Messages: 3468
Registered: June 2003
Location: Hendersonville, North Car...
Karma: 0
General (3 Stars)
Ah ok, a number divided by itself = 1.

If that doesnt get you there, nothing will.


WOL: Ob165ion Skype: Oblivion165 Yahoo Instant Messenger: CaptainJohn165
Re: OT: C++ Recursion [message #192154 is a reply to message #192146] Tue, 07 March 2006 21:33 Go to previous messageGo to next message
CPUKiller is currently offline  CPUKiller
Messages: 17
Registered: June 2005
Karma: 0
Recruit

Looking Recursively:

1 + ValueOf(5) (11%2-> 1, 11/2 -> 5)
	  1 + ValueOf(2) (5%2-> 1, 5/2 -> 2)
	      0 + ValueOf(1) (2%2-> 0, 2/2 -> 1)
	         1 + ValueOf(0) (1%2-> 1, 1/2 -> 0)



http://www.viralsound.com/get/cpukiller.php
Re: OT: C++ Recursion [message #192156 is a reply to message #192146] Tue, 07 March 2006 21:56 Go to previous messageGo to next message
Ryan3k is currently offline  Ryan3k
Messages: 363
Registered: September 2004
Location: USA
Karma: 0
Commander
CPUKiller has pretty much got it, I don't know C++ myself, but I know Java, and all you need to know is that the '%' operator is for modular division, and it gives you the remainder of a/b.

For example,
10 % 3 = 1
10 % 10 = 0
12 % 5 = 2

Another important note is that because it is an int, it will truncate decimals. In the first runthrough of ValueOf, when you divide 11 by 2, you get 5.5, right? Well, it won't round it up to 6. It truncates the decimal, and you end up with 5.

5 becomes the new 'N', passed as parameter to ValueOf... etc. etc.


Re: OT: C++ Recursion [message #192158 is a reply to message #192154] Tue, 07 March 2006 22:03 Go to previous messageGo to next message
icedog90 is currently offline  icedog90
Messages: 3483
Registered: April 2003
Karma: 0
General (3 Stars)
CPUKiller wrote on Tue, 07 March 2006 20:33

Looking Recursively:

1 + ValueOf(5) (11%2-> 1, 11/2 -> 5)
	  1 + ValueOf(2) (5%2-> 1, 5/2 -> 2)
	      0 + ValueOf(1) (2%2-> 0, 2/2 -> 1)
	         1 + ValueOf(0) (1%2-> 1, 1/2 -> 0)




Thanks a ton... I fully understand it now. That got rid of the lock in my brain.

Thanks everyone else. Rocked Over
Re: OT: C++ Recursion [message #192159 is a reply to message #192158] Tue, 07 March 2006 22:10 Go to previous messageGo to next message
Ryan3k is currently offline  Ryan3k
Messages: 363
Registered: September 2004
Location: USA
Karma: 0
Commander
Sometimes you just have to put it down and look at it later. When I took my Calculus II final last semester, I was so nervous and had been studying so much that I literally forgot Calculus for the first 10 minutes of the exam. I just let go for a little while, tried to calm down, then everything came back to me.

I forgot all of my +C's, but I still ended up with an A on it. Big Grin


Re: OT: C++ Recursion [message #192161 is a reply to message #192146] Tue, 07 March 2006 22:23 Go to previous messageGo to next message
icedog90 is currently offline  icedog90
Messages: 3483
Registered: April 2003
Karma: 0
General (3 Stars)
Yeah, that's pretty much what went on with me. Thanks for the advice. Waiting on it did help a lot.

...and nice job on the grade, hehe.

[Updated on: Tue, 07 March 2006 22:24]

Report message to a moderator

Re: OT: C++ Recursion [message #192162 is a reply to message #192146] Tue, 07 March 2006 23:20 Go to previous messageGo to next message
Dave Anderson is currently offline  Dave Anderson
Messages: 1953
Registered: December 2004
Location: United States
Karma: 0
General (1 Star)
Well, seems that I have learned a thing or two from this topic:

Quote:

For example,
10 % 3 = 1
10 % 10 = 0
12 % 5 = 2


I thank you very much for refreshing my memory. Very Happy

EDIT: Since this is the same subject, I just wanted to let y'all know that when I finish my website, (which is taking forever because it gets boring at times), I will have a complete section on C++ where you can go if you want to learn the basics of C++. It will be pretty explanatory and should be pretty straight foward. When I first learned C++, I pretty much went to my local library, checked out a C++ book, and was writing very basic programs within the hour I started reading.

My object for providing this section on my site, is I am hoping that others interested in C++ can use what I have learned to learn it themselves.


David Anderson
Founder, Software Consultant
DCOM Productions
Microsoft Partner (MSP)

[Updated on: Tue, 07 March 2006 23:25]

Report message to a moderator

Re: OT: C++ Recursion [message #192163 is a reply to message #192146] Tue, 07 March 2006 23:22 Go to previous messageGo to next message
icedog90 is currently offline  icedog90
Messages: 3483
Registered: April 2003
Karma: 0
General (3 Stars)
Modulus is a bitch... because it's easy to forget.
Re: OT: C++ Recursion [message #192217 is a reply to message #192146] Wed, 08 March 2006 15:32 Go to previous messageGo to next message
Sir Kane
Messages: 1701
Registered: March 2003
Location: Angerville
Karma: 0
General (1 Star)
Wonder what happens if you __forceinline that function lol

Proud N9500 and proud N6270 user. Creator of the IEE libraries (original bhs.dll) and the RB series software.
http://n00bstories.com/image.fetch.php?id=1189992501http://www.n00bstories.com/image.fetch.php?id=1257492907
Re: OT: C++ Recursion [message #192228 is a reply to message #192217] Wed, 08 March 2006 19:03 Go to previous message
=HT=T-Bird is currently offline  =HT=T-Bird
Messages: 712
Registered: June 2005
Karma: 0
Colonel
Silent Kane wrote on Wed, 08 March 2006 16:32

Wonder what happens if you __forceinline that function lol

If the argument was a constant-expression, I'd say that most sensible compilers capable of unit-at-a-time compilation would be able to evaluate the entire mess at compile time (it's a pure function).


HTT-Bird (IRC)
HTTBird (WOL)
Proud HazTeam Lieutenant.
BlackIntel Coder & Moderator.

If you have trouble running BIATCH on your FDS, have some questions about a BIATCH message or log entry, or think that BIATCH spit out a false positive, PLEASE contact the BlackIntel coding team and avoid wasting the time of others.
Previous Topic: RA2 Mission
Next Topic: Renegade Website
Goto Forum:
  


Current Time: Sat Nov 09 02:39:54 MST 2024

Total time taken to generate the page: 0.00970 seconds