illegal cases and breaks

i keep getting errors saying my cases and breaks are illegal because they can only be used in a switch...could anyone help me figure out why I'm getting these errors because they're definitely in a switch??

#include <iostream>
#include <iomanip>

const int LOOP_LIMIT = 16;

using namespace std;


char passenger_first_name;
char passenger_last_name;


int main ()
{
char menu_option (int a, char b, int c, double d, int e);
void get_data( int a, char b, int c, double d, int e);

int j= 0;
int number_of_taken_seats = j = 0;
for (j = 0, j<= LOOP_LIMIT; ++j;);

int k = 16;
int number_of_available_seats = k= 16;
int seat_id_number [16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,16};

cout<<"Welcome to the ISE Seating Program!"<<endl;

cout<<endl;

cout<<"To choose a function, enter its letter label and press <Enter>"<<endl;

cout<<endl;

cout<<"a) Show number of empty seats"<<endl;

cout<<"b) Show a list of empty seats"<<endl;

cout<<"c) Assign a customer to seat assignment"<<endl;

cout<<"d) Delete a seat assignment"<<endl;

cout<<"e) Quit the program"<<endl;

cin>>menu_option;

}


void get_data( int a, char b, int c, double d, int e)
{
int number_of_available_seats;
int seat_id_number [16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,16};

switch(char menu_option);
{
case 'a':
int k = 16;
do
{
cout<<number_of_available_seats<<endl;
--k;
} while (k<= LOOP_LIMIT);
cout<<endl;
break;

case 'b': //cout<<seat_id_numbers
switch (k)
{
case 0: seat_id_number[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
case 1: seat_id_number[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
case 2: seat_id_number[14] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14};
case 3: seat_id_number[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
case 4: seat_id_number[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
case 5: seat_id_number[11] = {1,2,3,4,5,6,7,8,9,10,11};
case 6: seat_id_number[10] = {1,2,3,4,5,6,7,8,9,10};
case 7: seat_id_number[9] = {1,2,3,4,5,6,7,8,9};
case 8: seat_id_number[8] = {1,2,3,4,5,6,7,8};
case 9: seat_id_number[7] = {1,2,3,4,5,6,7};
case 10: seat_id_number[6] = {1,2,3,4,5,6};
case 11: seat_id_number[5] = {1,2,3,4,5};
case 12: seat_id_number[4] = {1,2,3,4};
case 13: seat_id_number[3] = {1,2,3};
case 14: seat_id_number[2] = {1,2};
case 15: seat_id_number[1] = {1};

if (seat_id_number<1);
cout<< "We're sorry. There are no available seats."<<endl;
else if (seat_id_number <= LOOP_LIMIT)
cout<<"List of available seats: " <<seat_id_number[k]<<endl;
break;
}

case 'c'://cout<<seat_id_number<<endl;
cout<<"Please enter your first name and press <Enter>"<<endl;
cin>>passenger_first_name;
cout<<"Please enter your last name and press <Enter>"<<endl;
cin>>passenger_last_name;
for (int j; j<=LOOP_LIMIT; j++);
{
k = j-1;
if (j==1)
cout << "Your seat number is"<<passenger_last_name<<","<<passenger_first_name<<seat_id_number<<endl;
else if ((j >= 2) && (j <=LOOP_LIMIT))
cout<< "Your seat number is"<<passenger_last_name<<","<<passenger_first_name<<seat_id_number<<endl;
}
break;


case 'd':cout<<number_of_available_seats;// user input seat_ID. find way to add that deleted seat back to available seat. ++k?
break;
case 'e':cout<<"Thank you for your time, Goodbye!";
break;
}
}

{
system ("pause");

return 0;
}
Looking over it quickly, I remember an issue a while back about not being able to declare variables within a switch statement. Under case 'a', you're declaring k. Try moving the declaration outside of the switch and just assigning k values where you need.

You also don't have break statements in your nested switch statement.

Edit: You're also going to be going out of range with your nested switch statement. Your array is of size 16, so setting the elements at 16, which is already out of bounds, will also go out of bounds. Also, what's the purpose of that switch statement? That array is already set to numbers 1-16 from 0-15.

There is a few other errors with your code, and it might be better to rewrite most of the stuff. Also, it might be smart to add some comments in so that you, and more importantly, other know what your code is designed to do.
Last edited on
i tried taking out the declaration but then another errors comes saying k is undefined
Your main function ends right after you cin >> menu option. Everything after that is outside main(). You never call the get_data function in main.

int number_of_available_seats = k= 16;

Here you already assigned 16 to k on the line before it so it's not really necessary to do it again. Also, you defined another variable k inside get_data. That variable will hide one inside declared inside main once execution passes to get_data (once you get main to call get_data that is.)

Also, function declarations are usually placed outside of main after the using directives.

case 'b': //cout<<seat_id_numbers

This line everything after // is commented out. Maybe you intended that, not sure.

case 0: seat_id_number[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

Here you are trying to assign 16 different value to a single element of an array. Not really sure what you are trying to do in that switch anyway, especially since without any breaks with the cases execution will fall through all the ones after the first one it jumps to. Additionally, you don't have a close brace at the end of the switch, so the compiler thinks the if/else/if are part of the switch.

Also, please use the code tags (the <> button on the right) when posting code. It makes it alot easier to read and includes line numbers.
Last edited on
thanks so much you all!...but im still having issues with the cases and breaks, specifically the letter cases not the numbers
the purpose of this project is to make a seat reservation program for a flight. the scenario is that there are only 16 seats on the flight and that each person must choose the next seat (1st person must have seat one, 2nd person seat 2, etc.)...each case is there in the nested switch is there to show that number person (person 1, person 2, etc.) how many seats are left on the flight....also for this project we're only allowed to use what we've learned (including loops, arrays, if else statements, switch statements, boolean, functions, subprograms, and the basics)....i hope that helps to better understand what I'm doing
our build succeeded but nothing is displaying when we go to debug the program...help!

#include <iostream>
#include <iomanip>

const int LOOP_LIMIT = 16;

using namespace std;

char response;
char passenger_first_name;
char passenger_last_name;
void get_data( char a, char b, char c, char d, char e);

int main ()
{
char menu_option (char a, char b, char c, char d, char e);

int j= 0;
int number_of_taken_seats = j = 0;
for (j = 0, j<= LOOP_LIMIT; ++j;);

int k = 16;
int number_of_available_seats = k= 16;
int seat_id_number [16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

cout<<"Welcome to the ISE Seating Program!"<<endl;

cout<<endl;

cout<<"To choose a function, enter its letter label and press <Enter>"<<endl;

cout<<endl;

cout<<"a) Show number of empty seats"<<endl;

cout<<"b) Show a list of empty seats"<<endl;

cout<<"c) Assign a customer to seat assignment"<<endl;

cout<<"d) Delete a seat assignment"<<endl;

cout<<"e) Quit the program"<<endl;


}


void get_data( char a, char b, char c, char d, char e)
{
int number_of_available_seats;
int seat_id_number [16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,16};
int deleted_seat,j,k;
char response;
char menu_option;

switch(menu_option)
{
case 'a':

do
{
cout<<number_of_available_seats<<endl;
--k;
} while (k<= LOOP_LIMIT);
cout<<endl;
break;

case 'b':
switch (k)
{
case 0: seat_id_number[16] = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
break;
case 1: seat_id_number[15] = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
break;
case 2: seat_id_number[14] = (1,2,3,4,5,6,7,8,9,10,11,12,13,14);
break;
case 3: seat_id_number[13] = (1,2,3,4,5,6,7,8,9,10,11,12,13);
break;
case 4: seat_id_number[12] = (1,2,3,4,5,6,7,8,9,10,11,12);
break;
case 5: seat_id_number[11] = (1,2,3,4,5,6,7,8,9,10,11);
break;
case 6: seat_id_number[10] = (1,2,3,4,5,6,7,8,9,10);
break;
case 7: seat_id_number[9] = (1,2,3,4,5,6,7,8,9);
break;
case 8: seat_id_number[8] = (1,2,3,4,5,6,7,8);
break;
case 9: seat_id_number[7] = (1,2,3,4,5,6,7);
break;
case 10: seat_id_number[6] = (1,2,3,4,5,6);
break;
case 11: seat_id_number[5] = (1,2,3,4,5);
break;
case 12: seat_id_number[4] = (1,2,3,4);
break;
case 13: seat_id_number[3] = (1,2,3);
break;
case 14: seat_id_number[2] = (1,2);
break;
case 15: seat_id_number[1] = (1);
break;



{
if (number_of_available_seats < 1)
{
cout<<"We're sorry. There are no available seats."<<endl;
}

else if (number_of_available_seats <= LOOP_LIMIT)
{
cout<< "List of available seats: " <<seat_id_number[k]<<endl;
}

}


}
break;

case 'c':
cout<<"Please enter your first name and press <Enter>"<<endl;
cin>>passenger_first_name;
cout<<"Please enter your last name and press <Enter>"<<endl;
cin>>passenger_last_name;
for (int j; j<=LOOP_LIMIT; j++);
{
k = j-1;
if (j==1)
cout << "Your seat number is"<<passenger_last_name<<","<<passenger_first_name<<seat_id_number<<endl;
else if ((j >= 2) && (j <=LOOP_LIMIT))
cout<< "Your seat number is"<<passenger_last_name<<","<<passenger_first_name<<seat_id_number<<endl;
}
break;


case 'd':cout<<number_of_available_seats;
cout<<"Would you like to delete a seat?"<<endl;
if (response == 'Y')
{
cout<<"What is your seat number?"<<endl;
cin>>deleted_seat;
do
{
number_of_available_seats += 1;
case 200:
do
{

cout<<number_of_available_seats<<endl;

}while (k<= LOOP_LIMIT);
cout<<endl;
break;

case 300:
switch (k)
{
case 0: seat_id_number[16] = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
break;
case 1: seat_id_number[15] = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,deleted_seat);
break;
case 2: seat_id_number[14] = (1,2,3,4,5,6,7,8,9,10,11,12,13,deleted_seat);
break;
case 3: seat_id_number[13] = (1,2,3,4,5,6,7,8,9,10,11,12,deleted_seat);
break;
case 4: seat_id_number[12] = (1,2,3,4,5,6,7,8,9,10,11,deleted_seat);
break;
case 5: seat_id_number[11] = (1,2,3,4,5,6,7,8,9,10,deleted_seat);
break;
case 6: seat_id_number[10] = (1,2,3,4,5,6,7,8,9,deleted_seat);
break;
case 7: seat_id_number[9] = (1,2,3,4,5,6,7,8,deleted_seat);
break;
case 8: seat_id_number[8] = (1,2,3,4,5,6,7,deleted_seat);
break;
case 9: seat_id_number[7] = (1,2,3,4,5,6,deleted_seat);
break;
case 10: seat_id_number[6] = (1,2,3,4,5,deleted_seat);
break;
case 11: seat_id_number[5] = (1,2,3,4,deleted_seat);
break;
case 12: seat_id_number[4] = (1,2,3,deleted_seat);
break;
case 13: seat_id_number[3] = (1,2,deleted_seat);
break;
case 14: seat_id_number[2] = (1,deleted_seat);
break;
case 15: seat_id_number[1] = (deleted_seat);
break;
}
}while (k<= LOOP_LIMIT);
}
break;

case 'e':cout<<"Thank you for your time, Goodbye!";
break;
}
cout<<"Enjoy your flight!"<<endl;
system ("pause");

}
Please use code tags.
Topic archived. No new replies allowed.