validating

This is part of a function for booking seats, can anyone show me how to handle the validation below.To make sure that a seat that has X cannot be booked again.
I tried that but it seems not to be working.


if ((seats [i1][j1][k1] = 'B') || (seats [i1][j1][k1] ='I') || (seats [i1][j1][k1] ='W'))
{
seats[i1][j1][k1] = 'X';
}
else if (seats [i1][j1][k1] == 'X')
{
cout << "Sorry!! the Cabins is already booked" << endl;
break;
}
writeInformation();

I want you to notice the difference between the operators you use for equality checking in the if and else if statements.

1
2
3
4
5
6
7
8
9
10
11
//here you use = for equality checking
if ((seats [i1][j1][k1] = 'B') || (seats [i1][j1][k1] ='I') || (seats [i1][j1][k1] ='W'))
{
seats[i1][j1][k1] = 'X';
}
else if (seats [i1][j1][k1] == 'X') //here you use == for equality checking
{
cout << "Sorry!! the Cabins is already booked" << endl;
break;
}
writeInformation();

They are different, one is = and the other is ==. I ll let you find yourself which one is the right one ;)
Topic archived. No new replies allowed.