Hey guys, my friend helped me with a code, but I didn't get a chance to ask him about why col is subtracted by 65? Can anyone tell me what exact that line is suppose to do.
Thanks for dealing with me...the line is bold...

#include <iostream>			//preprocesser directives

using namespace std;       //prefix

void table(char seats[13][6]); 

int main()						///main
{
    char seats[13][6];			// array for seats
    int ticket, choice, rows, row, seated = 0, index= 0;      //ticket class, rows,  individual row
    char col;
    
table(seats);

    do
    {        
        system("cls");
        cout << "1. FirstClass\n";
        cout << "2.Economy Class\n";
        cout << "If you want to exit type 9\n";
        cout << "Enter your ticket type: ";
        cin >> ticket;
        
        if(ticket == 9)
           break;        
        else if(ticket == 2)
        {
           system("cls");
           cout << "1. Smoking\n";
           cout << "2. Nonsmoking\n";
           cout << "What section do you want to sit in? ";
           cin >> choice;
           
           if(choice == 2)
           {
               index = 2;
               rows = 7;
           }
           else if(choice == 1)
           {
               rows = 13;
               index = 7;
           }
        }
        else if(ticket == 1)
           rows = 2;    
        
        do
        {
        
           system("cls");
           cout << "\tA\tB\tC\tD\tE\tF" << endl;

           for(int i = index; i < rows; i++)
           {
               cout << "Row " << i+1 << "\t";

               for(int j = 0; j < 6; j++)
               {
                   cout << seats[i][j] << "\t";
               }
               cout << "\n";
           }
           
[B]           [U]cout << "What row do you want to sit in? ";
           cin >> row;
           cout << "What column do you want to sit in (ie A,B,C)? ";
           cin >> col;
           col -= 65;[/[/U]B]

           if(seats[row-1][(int)col] != 'X')
           {
                seats[row-1][(int)col] = 'X';
                seated = 1;
                cout << "\nSeated\n";
           }

           else
               cout << "\nSeat is already taken, choose another\n";
           system("pause");

        }while(seated == 0);
        seated = 0;
        index = 0;  

    }while(ticket != -1);
    
    
    system("pause");

    return 0;
}



void table(char seats[13][6])
{
	    for(int i = 0; i < 13; i++)
	{
		for(int j = 0; j < 6;j++)   
		{
			seats[i][j] = '*';
			if(j==0)		//A
				if(i==3 || i==6 || i==8)  //Row 4, 7,9
					seats[i][j] = 'X';
				else
					 seats[i][j] = '*';

			else if(j==1)		//B
				if(i==1 || i==4 || i==5 || i==7 || i==9)		//Row 2, 5,6,8,10
					seats[i][j] = 'X';
				else
					 seats[i][j] = '*';

			else if(j==2)			//C
				if(i==0 || i==2 || i==3 || i==8 || i==10 || i==11)		//Row 1, 3,4,9,11,12
					seats[i][j] = 'X';
				else
					 seats[i][j] = '*';

			else if(j==3)			//D
				if(i==1 || i==2 || i==4 || i==7 || i==8 || i==9 || i==11)			//Row 2, 3,5,8,9,10,12
					seats[i][j] = 'X';
				else
					 seats[i][j] = '*';

			else if(j==4)			//E
				if(i==0 || i==3 || i==6 || i==7 || i==9 || i==10 || i==12)			//Row 1, 4,7,8,10,11,13
					seats[i][j] = 'X';
				else
					 seats[i][j] = '*';			

			else if(j==5)			//F
				if(i==0 || i==1 ||  i==2 || i==3 || i==5 || i==6 || i==8 || i==9 || i==11)			//Row 1, 2,3,4,6,7,9,10,12
					seats[i][j] = 'X';
				else
					 seats[i][j] = '*';
		}
	}
}

You have to enter a character 'A', 'B', or 'C'. To convert that into a numerical integer 0, 1, or 2 you just have to subtract 65 because the decimal value of the characr 'A' is 65. Look up google for "ascii chart" and you will see the decimal values of all 255 possible characters, some printable and others are not.

But, that is not a good way to code that program. What will happen if you enter a '0' instead of 'A'? Subtracting 65 from '0' will produce a negative value because the decimal value of '0' is only 48.

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.