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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

possible use of ' ' before definition in function main()

Status
Not open for further replies.

rozzay

Programmer
Jan 3, 2002
142
0
0
US
Hello!

I am getting an error message of "Possible use of 'charSeatFull' before definition in function main(). I looked at the particular char and I don't refer it before the call only when I declare it. I don't understand of why could there be a possible use of before the function main.

Your help is appreciated.

#include <iostream.h>
#include <iomanip.h>
#include <cstring.h>
//=========================================================
class clFlight
{private:
int firstclasscnt;
int economycnt;
char charSection;
public:
clFlight();
int chkSection();
int assignSeat();
};
clFlight::clFlight()
{firstclasscnt = 0;
economycnt = 5;}

int clFlight::chkSection()
{char charReply;
cout << "/nPlease select 1 First Class or 2 Economy: ";
cin >> charSection;

if (charSection == '1'){
if (firstclasscnt < 5){
return 1;
} else {
cout << "/nFirst Class Section is Full. "
<< "/nWould you like the Economy Section instead?"
<< "/nPlease select Y or N: ";
cin >> charReply;
if (charReply == 'Y' || charReply == 'N' ||
charReply == 'y' || charReply == 'n') {
if (charReply == 'Y' || charReply == 'y') {
return 2;
} else {
cout << "/n================================"
<< "/n=The next flight will be in 3 hours.="
<< "/n============================";
return 0; }}}};
if (charSection == '2') {
if (economycnt < 10) {
return 2;
} else {
cout << "/nEconomy Section is Full. "
<< "/nWould you like the First Class Section instead?"
<< "/nPlease Select Y or N: ";
cin >> charReply;

if (charReply == 'Y' || charReply == 'N' ||
charReply == 'y' || charReply == 'n') {
if (charReply == 'Y' || charReply == 'y') {
return 1;
} else {
cout << "/n========================"
<< "/n=Next Flight will be in 3 hours. ="
<< "/n=========================";
return 0;}}}};
cout << "/n================================"
<< "/n= Invalid Input!! Please try again! ="
<< "/n===========================";
return 0;}

int clFlight::assignSeat()
{if (charSection == '1') {
firstclasscnt = firstclasscnt + 1;
return firstclasscnt; };
if (charSection == '2') {
economycnt = economycnt + 1;
return economycnt; }
else return -1;}
//==========================================================
class clDisplay
{private:
public:
void displayMenu();
void displayErrMsg();
void displaySection(char pass_section);
void displaySeat(int pass_seat);};

void clDisplay::displayMenu()
{
cout << "/n======================================="
<< "/n Rosalyn Airline Reservation System "
<< "/n=======================================";
}

void clDisplay::displaySection(char pass_section)
{
cout << "Your section is: " << pass_section << endl;
}

void clDisplay::displaySeat (int pass_seat)
{
cout << "Your seat is: " << pass_seat << endl;
}
//==========================================================
class clBoardingPass
{ private:
public:
void PrintBoardPass (int Section, int intSeat);
};
void clBoardingPass :: PrintBoardPass(int Section, int intSeat)
{
cout << endl;
if (Section == 1){
cout << "/n--------------------------------------"
<< "/n- Boarding Pass for Rosalyn Airline. -"
<< "/n- Section: First Class -"
<< "/n- Seat: " << intSeat << " -"
<< "/n-------------------------------------";
}
else{
cout << "/n------------------------------"
<< "/n- Boarding Pass for Rosalyn Airline. -"
<< "/n- Section: Economy -"
<< "/n- Seat: " << intSeat << " -"
<< "/n-----------------------------";
} }
//=======================================================
int main()
{
char charSeatFull;
char charFirstClassFull;
char charEconomyFull;
int flightchk;
int selectedSection;
int assignSeat;
clFlight obj1;
clDisplay obj2;
clBoardingPass obj3;
obj2.displayMenu();
while(charSeatFull != 'Y'){
flightchk = obj1.chkSection();
if (flightchk == 1 || flightchk == 2){
selectSection = flightchk;
assignSeat = obj1.assignSeat();
obj3.PrintBoardPass(selectSection, assignSeat);}
if (selectedSection == 1 && assignSeat == 5){
charFirstClassFull = 'Y'; };
if (selectSection = 2 && assignSeat == 10){
charEconomyFull = 'Y'; }
if (charFirstClassFull == 'Y' && charEconomyFull == 'Y') {
charSeatFull = 'Y'; } }
return 0;
}
 
You define charSeatFull in main and then without ever assigning you do:

Code:
  while(charSeatFull != 'Y'){

The reason that you are getting the error (actually, it should be a warning, not an error) is that you are referencing charSeatFull without it being initialized to a value. charSeatFull could hold any value, including 'Y' if it isn't initialized, and your while loop would never get executed.

In your definition initialize charSeatFull so that it has a value like:

Code:
  char charSeatFull='N';

and that will take care of the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top