Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,565 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,885 people online right now. Registration is fast and FREE... Join Now!




Recursion

 
Reply to this topicStart new topic

Recursion, Homework

christianlayman
9 Apr, 2008 - 05:16 PM
Post #1

New D.I.C Head
*

Joined: 9 Apr, 2008
Posts: 2

I need help writing a program that creates the following output

This was written by call number1
This was written by call number2
This was written by call number 3
This was written by call number 4
This was written by call number4
This was written by call number3
This was written by call number2
This was written by call number1

User is offlineProfile CardPM
+Quote Post

skaoth
RE: Recursion
9 Apr, 2008 - 05:42 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 343



Thanked: 10 times
Dream Kudos: 100
My Contributions
Here you go.

#include <iostream>
void main(void)
{
std::cout << "This was written by call number1" << std::endl;
std::cout << "This was written by call number2" << std::endl;
std::cout << "This was written by call number 3" << std::endl;
std::cout << "This was written by call number 4" << std::endl;
std::cout << "This was written by call number4" << std::endl;
std::cout << "This was written by call number3" << std::endl;
std::cout << "This was written by call number2" << std::endl;
std::cout << "This was written by call number1" << std::endl;

}

Honestly, you will only get help if you first show some effort.
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Recursion
9 Apr, 2008 - 07:51 PM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

code.gif
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Recursion
10 Apr, 2008 - 11:25 AM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
basic recursion. A recursive function is one that calls itself. Generally you define and "exit condition" in which the function does NOT call itself (else you tend to end up with an infinite loop).

so you need to make a function that:

prints a message
if the conditions are right, it calls itself
then it prints another message


its really that simple. Maybe 10 - 15 lines of code in all.
User is online!Profile CardPM
+Quote Post

JasonMcAuley
RE: Recursion
10 Apr, 2008 - 07:16 PM
Post #5

D.I.C Head
**

Joined: 10 Apr, 2008
Posts: 135


My Contributions
QUOTE(skaoth @ 9 Apr, 2008 - 06:42 PM) *

Here you go.

#include <iostream>
void main(void)
{
std::cout << "This was written by call number1" << std::endl;
std::cout << "This was written by call number2" << std::endl;
std::cout << "This was written by call number 3" << std::endl;
std::cout << "This was written by call number 4" << std::endl;
std::cout << "This was written by call number4" << std::endl;
std::cout << "This was written by call number3" << std::endl;
std::cout << "This was written by call number2" << std::endl;
std::cout << "This was written by call number1" << std::endl;

}

Honestly, you will only get help if you first show some effort.


I actually lol'd

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month