Hi,
while doing my assignment im somehow stucked somewhere which i didnt know why and i need some help. i have jus started learning abt c++. so im jus using some basic syntax

#include<iostream>
using namespace std;

int main()
{
	int selclass,i,position;
	char ch;
	int seats[100]={0}; //array
	while(true)
	{
                cout<<"Choose your class\n";
	cout<<"1.Business Class\n";
	cout<<"2.First Class\n";
	cout<<"3.Economic Class\n";
	cin>>selclass;
	switch(selclass)
	{
switch(selclass)
{
case 1:
cout<<"Seats available \n";
for(i=1;i<=20;i++)
{
if (seats[i] ==0) cout<<i<<" ";
}
cout<<"\nChoose your preferred seat\n";
cin>>position; //User's selected seat
if (position > 20)
{
cout<<"Seat Number: "<<position<<" is not available for Business Class\n";
}
else{
if (seats[position]=0)
cout<<"You have booked "<<position<<".Thank you\n"; //this sentence dont appear
seats[position]=1; //to change the array from 0 to 1
cout<<"You have booked "<<position<<".Thank you\n"; //this sentence appear if this line is added in but my array doesnt work
}
break;

i will require to add 1 more else at the very bottom for users who have selected an occupied seat. Please help

>>if (seats[position]=0)
You need to use the boolean operator == instead of the assignment operator =.

else
{
   if (seats[position]==0)
      cout<<"You have booked "<<position<<".Thank you\n";
      seats[position]=1; //to change the array from 0 to 1
}

In addition, pay a little more attention to proper indentation. That will allow you to spot errors easier. I suspect you want a set of curly braces around both of the lines after the above if, so the second line is processed only if the seat is available. If the second line isn't in curly braces you will be guilty of allowing double booking of seats, and I hate that when I fly.

commented: Yes to indentation and { } +29

thank you very much

how do i go about adding 1 more after

if (seats[position]==0)
cout<<"You have booked "<<position<<".Thank you\n"; //stucked
seats[position]=1;

in order for me to cout a sentence to prompt that the seat is taken

im very sorry abt the indentation as this is my 1st program =\ jus started 2 weeks ago

else
{
    if
    {
     }
    else
     {
     }
}

ic what you meant Lerner

Really thanks alot~

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.