User Changing Char Values in a 2D Array

Sep 24, 2016 at 11:48pm
I really would only like help on my last function in this program, I can handle the rest on my own, I'm simply stumped. The function void do_step is supposed to make the array start at the first element of the 2D array and repeatedly step forward by using int step, and places char ch at each spot "stepped" to.
Any help is appreciated.




#include <iostream>
#include <iomanip>

using namespace std;

const int max_size = 10;
void initialize (char table [max_size][max_size]);
void print (char table [max_size][max_size]);
void do_step (char table [max_size][max_size], int& step, char ch);

int main()
{
int step = 1;
char ch;
char table [max_size][max_size];

while (step != 0)
{
cout << "Enter A Step (enter zero to end):" << endl;
cin >> step;
cout << "Enter A Letter:" << endl;
cin >> ch;






}

return 0;


}

void initialize (char table [max_size][max_size])
{
int r;
int c;

for (r = 0; r < max_size; r++)
for (c = 0; c < max_size; c++)
table [r][c] = '.';
}

void print (char table [max_size][max_size])
{
int r;
int c;


for (r = 0; r < max_size; r++)
{
cout << endl;

for (c = 0; c < max_size; c++)
{
cout << setw (2) << table [r][c];
}
}
}

void do_step (char table [max_size][max_size], int& step, char ch)
{
char r;
char c;

for(r = 0; r < max_size; r++)
{
for(c = 0; c < max_size; c++)
{
table[step] = ch;
}
}
}
Sep 24, 2016 at 11:49pm
Also, I'd like to apologize for my bad formatting of this post, I'm new to this site.
Sep 25, 2016 at 12:12am
@juicyjuicekid

Well, you need a few small changes in the function.
1
2
3
4
5
6
7
8
9
10
11
12
13
void do_step (char table [max_size][max_size], int& step, char ch)
{
int r; // not char r;
int c; // not char c;

  for(r = 0; r < max_size; r+= step) 
  {
    for(c = 0; c < max_size; c+= step)
    {
      table[r][c] = ch;
    }
  }
}


That should do, except for the fact that you are not calling any function, after getting the step and ch.
Last edited on Sep 25, 2016 at 6:10pm
Sep 25, 2016 at 12:54am
Thank you very much, but yes I know that I have yet to use my functions in main. I was simply confused on how to write the function the correct way, I just haven't finished writing the whole program yet, which admittedly is very silly of me to do. I kinda jumped the gun on that part, again thank you.
Topic archived. No new replies allowed.