OT: C++ Recursion [message #192146] |
Tue, 07 March 2006 20:25 ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
icedog90
Messages: 3483 Registered: April 2003
Karma: 0
|
General (3 Stars) |
|
|
![http://img328.imageshack.us/img328/2981/die3qy.png](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 message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
![](http://renegadeforums.com/images/custom_avatars/3922.jpg) |
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 message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
![](/images/custom_avatars/996.jpg) |
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 #192156 is a reply to message #192146] |
Tue, 07 March 2006 21:56 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
![](http://renegadeforums.com/images/custom_avatars/3461.png) |
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.
A Path Beyond
|
|
|
|
|
|
Re: OT: C++ Recursion [message #192162 is a reply to message #192146] |
Tue, 07 March 2006 23:20 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) ![Go to next message Go to next message](/theme/Renegade_Forums/images/down.png) |
![](http://renegadeforums.com/images/custom_avatars/3922.jpg) |
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](images/smiley_icons/icon_biggrin.gif)
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 #192228 is a reply to message #192217] |
Wed, 08 March 2006 19:03 ![Go to previous message Go to previous message](/theme/Renegade_Forums/images/up.png) |
=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.
|
|
|