Good day to all of you. I'm looking for advice for my code below.
My code was intend to print out a set of asterisk base on the rows and columns in my array(cinema[20][23]).
The code works fine and i was trying to print out numbers (which is from 1 to 20) on the 1st row of my array.
Hope that any codemaster here can point out a little bit things that i have miss out.....

#include <iostream.h>

int main()
{	
	char alpha[20] = {' ','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S'};
	
	int row, column;
	char cinema[20][23] = {0}; 
	
	for(row= 0; row < 7 ; row++)
	{	cout<<alpha[row]<<" ";		
		for(column = 0; column < 23; column++)
		{	
			if(column == 0 || column == 5 || column == 18)
				{cout<<" ";
				}
			else if(column < 4)
				{	cout<<"* ";
				}
			else if(column > 4 && column <=17)
				{	cout<<"* ";
				}
			else if(column < 23)
				{	cout<<"* ";
				}
						
		}
		
		cout<<endl; //endline for one row
	}
	for(row = 7; row < 14 ; row ++)
	{	
		if(row == 7)
		{	cout<<" ";
		}
		else
		{	cout<<alpha[row - 1]<<" ";
			for(column = 0 ; column < 23; column++)
			{
				if(column == 0 || column == 5 || column == 18)
				{cout<<" ";
				}
				else if(column < 4)
				{	cout<<"* ";
				}
				else if(column > 4 && column <=17)
				{	cout<<"* ";
				}
				else if(column < 23)
				{	cout<<"* ";
				}
			}
		}
		cout<<endl;
	}
	for(row = 15; row < 20 ; row++)
	{	if(row == 15)
		{cout<<" ";
		}
		else 
		{	cout<<alpha[row - 3]<<" ";
			for(column = 0 ; column < 23; column++)
			{	if(column == 0 || column == 5 || column == 18)
					{cout<<" ";
					}
				else if(column < 4)
					{	cout<<"* ";
					}
				else if(column > 4 && column <=17)
					{	cout<<"* ";
					}
				else if(column < 23)
					{	cout<<"* ";
					}
			}
		}
		cout<<endl;
	}


	return 0;
}

You should use the C++ headers rather than c headers.
If you need to use a c header like <string.h> use <cstring>.

You probably have to fix the layout since 1-9 looks fine but when you get into double digits the column numbers don't line up.

#include <iostream> //use C++ headers
#include <cstring> //needed for memset
using namespace std; //used for cout and endl

int main()
{
	int row, column;
	char cinema[20][20];
	memset(cinema, '*', 20*20); //sets the cinema array to all '*'s

	for(row = 0; row < 20 ; row++)
	{
		if( row == 7 || row == 14 ) //adds row spacers
			cout << endl;
		cout << char(bool(row)*32+' '+row) << " "; //gets rid of the char array of A B C...
		for( column = 0; column < 20; column++ )
		{
			if(column == 0 || column == 4 || column == 16)
			{
				cout << " "; //adds column spacers
			}
			if( row == 0 ) //prints numbers along the top
				cout << column+1 << " ";
			else
				cout << cinema[row][column] << " "; //prints each seat
		}
		cout << endl;
	}
	return 0;
}

Thanks for the advices... but may i ask how did "char(bool(row)*32+' '+row)"
works to help print the alphabets???

This is just using the fact that bool(x) is 1 when x != 0 and bool(x) is 0 when x = 0.

When row is 0 you get

char(bool(0)*32 + ' ' + 0)
bool(0) = 0
anything times 0 = 0
and ' ' + 0 = ' '
so we output a ' '

Row 1 you get

char(bool(1)*32 + ' ' + 1)
bool(1) = 1
1 * 32 = 32
32 + ' ' + 1 = 65 (' ' = 32)
char(65) = 'A'

Row 2 you get

char(bool(2)*32 + ' ' + 2)
bool(2) = 1
1 * 32 = 32
32 + ' ' + 2 = 66 (' ' = 32)
char(66) = 'B'

and so on

This is just using the fact that bool(x) is 1 when x != 0 and bool(x) is 0 when x = 0.

When row is 0 you get

char(bool(0)*32 + ' ' + 0)
bool(0) = 0
anything times 0 = 0
and ' ' + 0 = ' '
so we output a ' '

Row 1 you get

char(bool(1)*32 + ' ' + 1)
bool(1) = 1
1 * 32 = 32
32 + ' ' + 1 = 65 (' ' = 32)
char(65) = 'A'

Row 2 you get

char(bool(2)*32 + ' ' + 2)
bool(2) = 1
1 * 32 = 32
32 + ' ' + 2 = 66 (' ' = 32)
char(66) = 'B'

and so on

Thank you for your explanation. But i still cant get this '32 + ' ' + 1 = 65 (' ' = 32)'...
how did the spacing(' ') double up the value???

The integer value of ' ' is 32 so you could replace ' ' with 32 in the equation if you wanted to.

Go to http://www.asciitable.com/ and you can see the values for all the characters.

The integer value of ' ' is 32 so you could replace ' ' with 32 in the equation if you wanted to.

Go to http://www.asciitable.com/ and you can see the values for all the characters.

Thanks again for your explanation...
Hope you have a good day....

thank u guys, i also having a same problem here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.