Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unreachable code in function

Status
Not open for further replies.

rozzay

Programmer
Jan 3, 2002
142
US
Hi again!! I am receiving an error message of:
Warning AIRLINE.CPP 124: Unreachable code in function DisplayAltChoice(int)
Error AIRLINE.CPP 124: Expression syntax in function DisplayAltChoice(int)
Error AIRLINE.CPP 135: 'DisplayAltChoice(int)' cannot return a value in function DisplayAltChoice(int)
Error AIRLINE.CPP 137: Declaration terminated incorrectly

Below is the coding below. Any help is greatly appreciated!!

//Airline.cpp
#include <iostream.h>
#define YES 1
#define NO 2
#define First_Class 1
#define Economy 2

void DisplayMenu(void);
int getMenuSelection(void);
int AssignSeats(int section);
int SectionFull (int section);
char getAltResponse (void);
char PlaneFull (void);
void DisplayMenuErr(void);
void DisplayAltChoice(int section);
void DisplayNextFlight(void);
void DisplayFlightDepart(void);
void DisplayBoardPass(int section, int seatnbr);
void DisplayEndMenu(void);

int FirstClassAssign = 0;
int EconomyAssign = 0;
int FirstClassSeatNbr = 0;
int EconomySeatNbr = 4;
char response;

int main(void)
{
int section;
int seatnbr;
do
{
DisplayMenu();
section = getMenuSelection();
if (SectionFull(section) == NO)
{
seatnbr = AssignSeats(section);
DisplayBoardPass(section, seatnbr);
}
else
{
DisplayAltChoice(section);
response = getAltResponse();
if (response == 'Y')
{
section = (section == First_Class) ? Economy : First_Class;
seatnbr = AssignSeats(section);
DisplayBoardPass(section, seatnbr);
}
else
DisplayNextFlight();
}
} while (PlaneFull() == NO);
DisplayFlightDepart();
return 0;
}
void DisplayMenu()
{
cout << endl
<< &quot;Menu of Seating Options&quot; << endl
<< &quot; 1) First Class&quot; << endl
<< &quot; 2) Economy&quot; << endl
<< &quot;Please enter your choice: &quot;;
return;
}
int getMenuSelection ()
{
int selection;
cin >> selection;
if ((selection != First_Class) && (selection != Economy))
{
DisplayMenuErr();
return getMenuSelection();
}
return selection;
}
int SectionFull(int section)
{
if (section == First_Class)
return (FirstClassSeatNbr == 5);
else
return (EconomySeatNbr == 10);
}
int AssignSeats(int section)
{
if (section == First_Class)
{
FirstClassSeatNbr++;
return FirstClassSeatNbr;
}
else
{
EconomySeatNbr++;
return EconomySeatNbr;
}
}
void DisplayMenuErr()
{
cout << endl
<< &quot;Incorrect choice!&quot; << endl
<< &quot;Please select again.&quot; << endl;
return;
}
void DisplayBoardPass(int section, int seatnbr)
{
cout << endl
<< &quot;Boarding Pass for Rosalyn's Airline International&quot; << endl
<< &quot;Section: &quot; << section << endl
<< &quot;Seat number: &quot; << seatnbr << endl
<< endl;
return;
}
void DisplayAltChoice(int section)
{
cout << endl
<< &quot;The &quot; << ((section == First_Class) ? &quot;First Class &quot; : &quot;Economy&quot;)
<< &quot;section is full.&quot; << endl
<< &quot;Would you like to reserve a seat in the &quot;
<< ((section == First_Class) ? &quot;Ecomony &quot; : &quot;First Class &quot;)
<< &quot;section?(Y/N): &quot;;
return;
)
char getAltResponse()
{
cin >> response;
if (response == 'y')
response = 'Y';
else if (response == 'n')
response = 'N';
if ((response != 'Y') && (response != 'N')
}
DisplayMenuErr();
return getAltResponse();
}
return response;
}
char PlaneFull (void)
{
if ((SectionFull(First_Class) == YES) && (SectionFull(Economy) == YES))
return = YES;
else
return = NO;
}
void DisplayNextFlight()
{
cout <<&quot;Next Flight leaves in 3 hours.&quot;;
return;
}
void DisplayFlightDepart()
{
cout <<&quot;Flight now ready for departure.&quot;;
return;
}
void DisplayEndMenu()
{
cout << &quot;Thank You for using Rosalyn's Airline Reservation System!&quot; endl
<< &quot;Please come again and Have a Nice Day!&quot; endl
return;
}
 
Let's guess, you want someone to read your code, compille it instead of you and you to look at it and post something more?

Ion Filipski
1c.bmp
 
I apologize I am unfamilar with Borland C++ and not quite friendly with this and still trying to learn what the error messages means and etc. Your help is greatly appreciated.
 
Oh I found what the deal is I had entered a ) instead of a } again I apologize for your time just learning as I go along.

Thanks though!
 
Without bad feelings:
If you want to be a programmer you must be very hard :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top