Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 25th, 2006, 7:04 PM   #1
browning_man9
Newbie
 
Join Date: Sep 2005
Posts: 5
Rep Power: 0 browning_man9 is on a distinguished road
c++ recursion question

I am a beginning programmer and I am having difficulty grasping the concept of recursion........Here's what I am talking about:


#include <iostream>

using namespace std;

void write(int n);
int count=0;
int main () {
write(3069);
return 0;
}

void write (int n)
{
if(n>1){
write(n/10);
cout << n%10;
}
}

/* RESULTS:
3069
*/

This is just a simple example that will illustrate my question....When tracing this programming, write enters with 3069, then it sends it 306, then it sends it 30, then it sends write 3.......my question is how come (when you mod it by 10) it prints out the number in the same order. I guess what I am really asking is how does the recursive calls sort of stay "suspended" without anything happening to it....I guess what I am asking is for someone explain to me how to properly trace this......Thank you for your time. Your response is appreciated!
browning_man9 is offline   Reply With Quote
Old Jan 25th, 2006, 7:08 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
YOU should spend some time reading the forum's FAQ/Rules and a "How to Post..." thread. Anything less is rude to those from whom you are seeking help. Put your code in tags. Thanks for your time, your appropriate response will be appreciated.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 25th, 2006, 7:14 PM   #3
browning_man9
Newbie
 
Join Date: Sep 2005
Posts: 5
Rep Power: 0 browning_man9 is on a distinguished road
YOU are right. I am so very sorry and I send my deepest apology's that my thread isn't properly formatted. I should have known better than to ask for help because I am only trying to better myself. I hope that not everyone has the same attitude as you. Yes, it may be true that I should have read the "how to post forum," but the fact of the matter is I have more things to do with my time than to sit and read such nonsense. I refuse to return to this forum, and I hope that when I attain my degree, I don't become as rude as you. Thank you for your time.
browning_man9 is offline   Reply With Quote
Old Jan 25th, 2006, 7:17 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You should check my other responses before you accuse me of not being helpful. YOU are being rude. This is a place to get help. The least you can do is check the rules of the community you are appealing to. If you have better things to do then read our "nonsense" guidelines, I assure you, WE have better things to do than help a big-headed, egoistical dummy.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 25th, 2006, 7:20 PM   #5
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Quote:
Originally Posted by browning_man9
Yes, it may be true that I should have read the "how to post forum," but the fact of the matter is I have more things to do with my time than to sit and read such nonsense.

Those that could potentially help you have more things to do with their time then help an ungrateful poster who seeks the knowledge of others twho ask nothing in return.

EDIT: Oops, I guess you felt the same way DaWei :p
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Jan 25th, 2006, 7:25 PM   #6
browning_man9
Newbie
 
Join Date: Sep 2005
Posts: 5
Rep Power: 0 browning_man9 is on a distinguished road
dummy eh? I was being rude, but that is only becuase you were being rude... I never called you any names becuase I will not stoop that low. However, the nice thing to do would have been to answer my question and say next time, why don't you read our "how to post" article so you can fit in as a member of this community.
browning_man9 is offline   Reply With Quote
Old Jan 25th, 2006, 7:46 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You want free advice. You don't want to pay the price of being civil enough to check the culture before you get your freebies. You want to do it "next time." With your attitude, you need to go back to mama and get your sugar teat and you pat on the ass for being a good little boy. You won't get it in the real world, with your attitude. Have your hand measured for a mop handle. If you don't change, you'll be a janitor.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 25th, 2006, 7:48 PM   #8
browning_man9
Newbie
 
Join Date: Sep 2005
Posts: 5
Rep Power: 0 browning_man9 is on a distinguished road
hahaha.....wow....what a waste of time......im outta here......
browning_man9 is offline   Reply With Quote
Old Jan 25th, 2006, 7:51 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You keep promising, but you don't deliver....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 26th, 2006, 6:00 PM   #10
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
browning_man, accepting correction is sometimes hard, just look at all those disobedient children out there. But grow up, and listen to what is said. You got a lot to learn, as do we all.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC