Aligning Characters

I'm struggling to align my '*" perfectly. I have made an multi dimensional array that will intilize each element to "*" and then I want to out put that in a certain way. As you guys can read my function here, on row 10, row 11,row12, row 13, my "*" become distorted from the previous rows. For instance this is what it looks like

Row 1*
Row 2*
row 3*...
row 10 *
row 11 *
row 12 *
Row 12 *


As youcan see that from row 10-13, the stars suddenly shift one unit to the right. I want all the stars to be perfectly aligned so any help would be preferred :)Thank you guys :)

checkout iomanip ( setw specifically )
http://www.cplusplus.com/reference/iomanip/
without knowing what your program looks like, perhaps you could use something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

int biggestRowName;
int numRows;
string rowName[numRows];
int row[numRows];

...


for(currentRowIndex = 0; currentRowIndex < numRows; currentRowIndex++)
{
cout << rowName[currentRowIndex];
for(i=rowName[currentRowIndex].length(); i<biggestRowName; i++) cout << ' ';
cout << row[currentRowIndex] << endl;
}


As always this is off the cuff and probably won't work first time, but the magic is using a for loop, initialise it to the length of your row name, and print spaces until it is equal to the longest row name...

Dax.

sorry guys. I thought I had posted my code already, but here it is :D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void seat_open(char seats[][5],int seatsize)
{
	//Display seat number
	cout<<" "<<"\tA\t"<<"B\t"<<"C\t"<<"D\t"<<"E\t";
	cout<<"\n\n";
	int row=0;
	int col=0;
	for(row=0;row<seatsize;row++)
		{
			cout<<"Row " <<row+1;
			for(col=0;col<5;col++)
			{
				cout<<right;
				cout<<setw(7);
				seats[row][col]='*';
				cout<<seats[row][col];
				cout<<"\t";
			}
			cout<<endl;
		}

}
Topic archived. No new replies allowed.