Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:45:57+00:00 2026-06-17T21:45:57+00:00

As you probably gathered from the title I’m having an error initialising the variable

  • 0

As you probably gathered from the title I’m having an error initialising the variable ‘passNum’ in the constructor of my file ‘booking.h’

The file contains the booking class for a flight reservation program and I’d like to initialise passNum to 0 because initially there are no passengers on the flight. However I keep getting the message “flight is full” which was in place for the user to see whether there was any space left on the flight or not. SO, to see the error I added a cout in order to see what number was actually stored in passNum. The output was ‘28080747’ however the number changes every time I compile and run.

Booking file…

//Booking class - Scotia Airlines
//Zac Mazs
//This class will reserve a seat for passenger


#include <iostream>
#include <string>

#include "flight.h"

using namespace std;

class Booking{

public:
    // default constructor
    Booking()
    {
    int passNum = 0; // initialise passenger number to 0
    totalSeats = 24; // total seats on plane
    fName = "empty";
    sName = "empty";
    busName = "empty";
    }
    // accessor methods

    void setPassNum(int p){passNum = p;}

    string getFname(){return fName;}
    string getSname(){return sName;}
    string getBusName(){return busName;}


    void addBooking()
    {

    if (passNum >= totalSeats) // if the number of passengers exceeds 24 then display flight-full message
        {
            cout << passNum;
            cout <<"Flight is full";
        }
        else
            {
                cout << "\tBooking Menu \n\n";
                cout << "Please select ticket type: \n";
                cout << "1- Business \n";
                cout << "2- Western Isles \n";
                cout << "3- Ordinary \n";
                cin >> livesAt;

                    // This will be used to calc total cost for each passenger dependant on ticket type
                    if(livesAt == 1)
                        {
                        discount = 0.75;
                        cout << "Please enter your business name\n";
                        cin >> busName;
                        }

                        else if (livesAt == 2)
                            {
                            discount = 0.90;
                            }

                        else if(livesAt == 3)
                            {
                            discount = 1.0;
                            }
                        else
                        {
                            cout << "Error, please choose 1,2 or 3";
                        }

                // Calculation - Standard ticket price is 60 Beans
                tickPrice = 60.0;
                tCost = (tickPrice * discount);



            bool booked = false;
                for(int ROW = 0; ROW < 4 && !booked; ROW++)
                    {
                        for(int COL = 0; COL < 6 && !booked; COL++)
                        {
                            if(f.isAvailable(ROW,COL) == true)
                            {
                            cout << "Please enter your first name \n";
                            cin >> fName;
                            cout << "Please enter your second name \n";
                            cin >> sName;
                            //create new string fullName from fName and sName
                            fullName == fName + " " + sName;

                            f.setName(ROW,COL, fullName);
                            f.setAvailable(ROW,COL,0);

                            f.seatArray[ROW][COL].available++;

                            booked = true;
                            // increment pass num/decrement totalSeats
                            totalSeats--;
                            passNum++;

                            // Message on screen for customer displaying cost of flight
                            cout << "*******************************\n";
                            cout << "\tBooking for "; cout << fName + " " + sName; cout << " confirmed.\n";
                            cout << "\tTotal cost = " << tCost << " GBP.\n";

                            }//end of if
                        }//end of for2
                    }//end of for1
            }//end else
    }// End of addBooking function

private:
//Declare all variables

string fName, sName, busName, fullName;
int livesAt, totalSeats;
int passNum;

float discount, tickPrice, tCost;

Flight f;
Seat s;
Passenger p;
};// End of addBooking class

Any thoughts? I really appreciate the help!

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:45:58+00:00Added an answer on June 17, 2026 at 9:45 pm

    In the constructor, passNum is declared locally (it hides the private class-level definition).

    Change to:

    Booking()
    {
        /*int*/ passNum = 0; //initialise passenger number to 0
        totalSeats = 24; // total seats on plane
        fName = "empty";
        sName = "empty";
        busName = "empty";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Probably problem with the php file which contains the following code: <?php mysql_connect(localhost,root,); mysql_select_db(deal);
Probably something really simple, but I'm having some real trouble with it. I have
As far as I know, and have gathered from other SO posts, there are
Probably a simple one but I have file paths like /var/www/html/mysite/releases/20130123113638/public_html/images/image.jpg where the release
Probably just another silly pointer issue from a C newbie. Couldn't figure this one
Probably simple, but I seem to be missing something. Two Models: public class Hardware
Probably not the best title, but I'll explain: I have an array of objects
Probably not the clearest title, but here goes - I need to display two
probably a really dumb question, but I keep getting the above error with the
probably a simple question but I seem to be suffering from programmer's block. :)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.