multiple string array to 2d array?

I've created this array of strings, and was wondering if i could convert this completely into a 2d array whilst maintain functionality of the value swapping?

I've also noticed that when entering some values it seems to output some extra array layers on top of the previous ones. Why is this?

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main ()

{
	bool exit = true;
	int row, col;
	char change;
	const int size = 8; 
	string displaystring0(8,'*');
	string displaystring1(8,'*');
	string displaystring2(8,'*');
	string displaystring3(8,'*');
	string displaystring4(8,'*');
	string displaystring5(8,'*');
	string displaystring6(8,'*');
	string displaystring7(8,'*');

	while (exit)
	{

	string arr[size];

		int rows = 0;

		arr[rows++] = displaystring0;
		arr[rows++] = displaystring1;
		arr[rows++] = displaystring2;
		arr[rows++] = displaystring3;
		arr[rows++] = displaystring4;
		arr[rows++] = displaystring5;
		arr[rows++] = displaystring6;
		arr[rows++] = displaystring7;

		for (int i = 0; i < rows; i++)
		{
			cout << arr[i] << endl;
		}
		
		cout << endl;

	cout << "Please select a row 0-7 (-1 to exit): ";
	cin >> row;
	cout << endl;

	if (row == -1) 
	{exit = false; break;}
	
	
	else 
	{

		cout << "Please select a column 0-7: ";
		cin >> col;
		cout << endl;
		
		
		cout << "Please enter a character: ";
		cin >> change;
		cout << endl;

		if (row == 0)
		{

			displaystring0 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr << endl;
			}
		}

		else if (row == 1)
		{

			displaystring1 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else if (row == 2)
		{

			displaystring2 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else if (row == 3)
		{

			displaystring3 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else if (row == 4)
		{

			displaystring4 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else if (row == 5)
		{

			displaystring5 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else if (row == 6)
		{

			displaystring6 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else if (row == 7)
		{

			displaystring7 [col] = change;

			for (int i = 0; i < row-1; i++)
			{
				cout << arr[i] << endl;
			}
		}

		else
		{

	cout << "You have selected an invalid value. Please try again" << endl;

		}

	}


	}

}


Also is there a way of checking the values against a range to make sure its valid? Entering a value for column or row that isnt in the range leads to some dizzying results!
Last edited on
Also is there a way of checking the values

use a debugger and set some breakpoints
Topic archived. No new replies allowed.