Recursion Problem

This is the 2D array board.

Hi, I am a beginner in C++ programme and I am very confused with recursion.

How to use recursion to write these two function when the player input the row and column. Please give me some hints and an example for me, thanks.

And I want to have one extra function that when the writer input a sentence, it will appear on the board, please tell me briefly how to do that and give some simple example for me to follow. Thanks

void makeHive(char canvas[MAX_ROW][MAX_COL], int row, int col, int depth)
void make triangle(char canvas[MAX_ROW][MAX_COL], int row, int col, int layer)

[Code]
void printCanvas(char canvas[MAX_ROW][MAX_COL])
{
cout << "The current canvas: " << endl;
cout << " " ;
for (int i=0; i<MAX_COL; i++)
cout << i % 10;
cout << endl;
cout << " //" ;
for (int i=0; i<MAX_COL; i++)
cout << "=";
cout << "\\\\" << endl;
for (int i=0; i<MAX_ROW; i++){
cout << i % 10 << "||";
for (int j=0; j<MAX_COL; j++){
if (canvas[i][j] == NULL_CHAR)
cout << ' ';
else
cout << canvas[i][j];
}
cout << "||" << endl;
}
cout << " \\\\";
for (int i=0; i<MAX_COL; i++)
cout << "=";
cout << "//" << endl;
}
[Code]
I think you'll have to give some more information before we can help you.
How to use recursion to write these two function when the player input the row and column

You haven't said what the functions are supposed to do. How can tell you how to write them without knowing what they are supposed to do?
And I want to have one extra function that when the writer input a sentence, it will appear on the board, please

Do you mean the user enters "Have a nice day" and the board contains
H || A || V || E || || A || || N || I || C || E || || D || A || Y ||
or something else? Where in the board should this appear?

Please read this post on how to ask a good question:
http://www.cplusplus.com/forum/beginner/1/


This is a continuation of OP’s recursion thread here: http://www.cplusplus.com/forum/general/251737/

I am not sure whether he is just trolling for code or what. He doesn’t seem to interested in getting actual help understanding the material...
Thanks Duthomhas , your previous information was very useful.
I know how to write the basic 4 function of straight line, vertical line
but this time is a little bit different.

Hive pattern is like binary tree
such as like this
_/
_/ \
\
Even the for loop , I don't know how to print is out. So I don't know how to transfer to recursion.

for your question , I am sorry for this. I always want to example because it is very useful for me to understand it.
Ah, good. Sorry for doubting you, and I am very pleased you got it figured out.

You've got to figure out how to break it into pieces.

Honestly, it often helps to use a piece of paper and a pencil (and even some scissors) to play with it — though you could play around in a text editor too.

Consider, you draw the honeycomb in lines — the output is done line-by-line, so your drawing has to work line-by-line as well.


Hint: solve the triangle problem first. If you can create output that does something like this:

    *
   ***
  *****
 *******
*********

...then you are well on your way to figuring out the honeycomb. Hint #2:

  ****
 ******
********
********
 ******
  ****


Don't worry so much about recursion or iteration while figuring out how to print it; figure out how to do it in repeating pieces. The triangle and honeycomb are very much like the straight line, except now you are dealing with two dimensions of things repeating. This means that each part of the shape will involve two levels of recursion.
  • one part for the vertical stuff (things that repeat across lines)
  • one part for the horizontal stuff (things that repeat on a single line)

Also, just like the triangle, it is ok if there is an offset each line.

This stuff is not particularly easy, especially when you are first learning it. But you can do it. It just takes struggling with it a bit.

Try things. See what parts worked, what parts didn’t. Keep going.
Topic archived. No new replies allowed.