cout did not appear and Nesting IF ELSE

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

my codes:

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;
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;
}
break;


i will require the following
1. wrong seat selected (done)
2. correct and array changed from 0 to 1 (done)
3. 1 more to let the user know that they have chosen an occupied seat (HELP!)
if (seats[position]=0) is an assignment; try ==.
use [code][/code] tags instead of [quote][/quote] tags when posting code.

here is your code again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
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; 
}
break;


Have a really good hard look and copmapre Line 16 (incorrect) with the way you
have written Line 7 (correct)
I am very sry but i just started this course 2 weeks ago.
Let me explain in a more clearer way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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;
seymore15074 posted the actual answer just before I posed my comments.
Topic archived. No new replies allowed.