Read Characters in 1 row of a 2D Array

Hello, im working on an array and need some help with my for loop. My program asks the user for a starting position in the array. The program needs to enter a letter in that position, and then enter *'s all across the same row and colum as the starting position of the letter. Im having trouble with the for loops that i need to enter and keep looping to fill the same rows and columns. I know i need multiple loops, but this one im trying to enter *'s just in the same row for now. The loop im having a problem with is this:

1
2
for (row = r+1; row <= 8; row++)
      board [row][col] = ' * ';


Any help would be great. But here is my full code. I really just need help with how to enter characters only into 1 row or column of an array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std; 

void init_board (char board [8][8]);
void move_queen (char board [8][8], int row, int col);
void move_knight (char board [8][8], int row, int col);
void print_board (char board [8][8]);

int main()
{
    char board [8][8];
    char input;
    
    init_board (board);
    
    cout << "Enter q (queen), k (knight) or e (end): " << endl; 
    cin >> input;
    while (input != 'e')
    {
          
          if (input == 'q')
          {
             move_queen (board, 8, 8);
             print_board (board);
             system("PAUSE");
             return 1;
          }
             
          if (input == 'k')
          {
          move_knight (board, 8, 8);
          return 1;
          }
    }
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


void init_board (char board [8][8])
{
     int row, col;
     
     for (row = 0; row < 8; row++)
         for (col = 0; col < 8; col++)
         board[row][col] = '.';

}


void move_queen (char board [8][8], int row, int col)
{
     int r, c;
     
     cout << "Enter starting row: " << endl;
     cin >> r;
     cout << "Enter starting column: " <<endl;
     cin >> c;
     
     board [r-1][c-1] = 'q';
     
     for (row = r+1; row <= 8; row++)
          board [row][col] = ' * ';
     
}


void move_knight (char board [8][8], int row, int col)
{
     int r, c;
     cout << "Enter starting row: " << endl;
     cin >> r;
     cout << "Enter starting column: " <<endl;
     cin >> c;
    
     
}


void print_board (char board [8][8])
{
     int row, col;
     
     for (row = 0; row < 8; row++)
     {
         for (col = 0; col < 8; col++)
         cout << board[row][col] << " ";
         
     cout << endl << endl;
     }
     
     cout << endl;
}
Topic archived. No new replies allowed.