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] = '*';
}
}
}