Help with this array

Hi here is my array, that prints out a grid, I want to get the Char X in rows D5 and E6, how can i do 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
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
	void seats();
	char seatPlan[10][6];
	char varStore =65;
	char character= 'X';
	bool correct_no =false;
	int row;
	int convert;
	char col;
	for(int row=0; row<10; row++)
	{
		varStore=65;
		for(int col=0; col<6; col++)
		{
			seatPlan[row][col] = varStore++;
		}
	}
	for (int row=0; row<10; row++)
	{
		cout<<"\n"<<row+1<<"\t";
		for (int col= 0; col<6; col++)
		{
			cout<<seatPlan[row][col]<<"\t";//prints grid
		}
		
	}
	
	cout<<"\n\n";	
	return 0;
}


Thanks for any help
D is the 4th letter of the alphabet.
So I guess D5 means you have to insert 'X' at the 4th row/ 5th column or 4th column/ 5th row of seatPlan.
i tried doing that but for some reason it did not work
You may be getting DATA confused with Display.
Take, for example, that a 2-d array is actually a long 1-d array - so-
1,2,3,
4,5,6,
7,8,9,

is actually [1,2,3,4,5,6,7,8,9,]

so your 5x10 array
abcde
abcde
abcde
abcde
...
abcde

can be thought of as,

ABCDEabcdeABCDEabcdeABCDEabcde ... ABCDE

so, then to calculate Row "D" and Col "5"
it would be the 5th grouping of "D"'s

ABCDEabcdeABCDEabcdeABCDEabcde ... ABCDE
.......1.......2........3........4........X <---

Once your DATA is installed correctly,
then you can print your grid with what-ever "X"'s you wish.

To position your array pointer, you can use a dbl loop as you currently have, or NO loop.

in a dbl loop:
loop 1 = 1 to 4 // "D"
loop2 = 1 to "5"
array [pointer] = "X"

or NO loop,
pointer= row x col
array[pointer] = "X"

Last edited on
Ok, i see the logic, how would i do that. I am very new to programming and have not even covered pointers yet. Is there any other way to do it.

In my program so far i can get these user to place X. so they are presented with an option:

Please enter col A
Please enter Row: 5

and then the grid will print

1 A B C D E F
2 A B C D E F
3 A B C D E F
4 A B C D E F
5 X B C D E F
6 A B C D E F
7 A B C D E F
...
10 A B C D E F

based on there choice, i thought i could have just simply put a statement in telling the program where i want X, but this does not seem to work
I need to put X in the grid, as an array, and i will need to people to attach a persons name to that arrays, so that when yoou check who is sitting in D5, it will come up with the person sitting there?
Last edited on
Can anyone help me please?

1.) Do you actually update the display?

2.) If you want to attach names to the people please use string variables instead of messing around with char-pointers /-arrays.
Strings are more C++, easier and better to overview and handle.

Btw, if you start a project like this I urgent recommend learning about pointers..!
They aren't as complicated as is might seem ;3


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
#include <cstdlib>
#include <iostream>

using namespace std;


//you probably want to redraw the array when you've changed something
//so we'll make an extra function
void display (int** seats, int row_number, int col_number) {
     
     for (int row_index = 0; row_index < row_number; row_index++){
         for (int col_index = 0; col_index < col_number; col_index++) {
             
             cout << char (seats[row_index][col_index]) << " ";
         }
         cout << endl;
     }   
     
     cout << endl;
     
}
             
int main(int argc, char *argv[])
{
    
    int row = 10;
    int col = 6;
    
    
    int **seats; // here i would suggest a string pointer
    //I use a pointer instead of an array
    //because otherwise the function doesn't want to work
    
    seats = new int* [row];
    for (int i = 0; i < row; i++) 
        seats[i]= new int[col];
    
    
    //initializing the pointer
    for (int row_index = 0; row_index < row; row_index++){
         for (int col_index = 0; col_index < col; col_index++) {
             seats[row_index][col_index] = 'A'+col_index;
         }
     } 
    
    display (seats, row, col);
    
    
    // change seat pointer e.g: D6
    // D = 4, but since we're dealing with indices we write 4-1 = 3
    seats [3][5] = 'X';
    //we could also let the user change this number it doesn't matter
    
    display (seats, row, col);
    
    
    cin.get();
    
    return EXIT_SUCCESS;
}



I hope I could adress the right problems ^_____^"
DonLuccar
Topic archived. No new replies allowed.