Hello. My first thread here @ daniweb.

Im stuck on some source code.

I am trying to create a small program that allows user to input '1' or '2' for class selection on an airplane. 1 for first 2 for economy. the plane capacity is 10, which is also the [array] size. If First Class is full (1-5) cout << "Can we move you to economy" and vice versa. Im having a tough time implementing an array to carry this out and allows the user to fill the capacity without over booking. Here's what i have so far, its pretty far off because I was stuck awhile ago so I created this ugly alternative, but it does basically what i want it to do ish.

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <iomanip>
using std::setw;

int main()
{
    const int capacity = 10;
    int plane[capacity] = {0};
    int decision;
    int firstclass = 5;
    int economy = 5;

    cout << "        Hello and Welcome to UNA (United Nerd Air)     " << endl;
    cout << "   Looks Like You're Looking to Purchase Tickets Today?" << endl;

        for (int i = 0; i <= 9; i++)
            {

    cout << endl << setw(45) << "First Class or Economy?" << endl;  
    cout << setw(42) << "( 1 ) or ( 2 )"            << endl;
    cin >> decision;

    if (decision == 1)
    {
        cout << setw(45) << "First Class has been selected" << endl << endl;
        cout << setw(20) << --firstclass << setw(15) << " First Class seats remain." << endl;
            if (firstclass < 1 && economy >= 1)
                cout << setw(45) << "First Class is booked. Economy?" << endl;
    }
    else

        if (decision == 2)
        {
            cout << setw(45) << "Economy has been selected" << endl << endl;
            cout << setw(20) << --economy << setw(15) << " Economy seats remain." << endl;

            if (economy < 1 && firstclass >= 1)
                cout << setw(45) << "Economy is full. First Class?" << endl;

        }
        else
            cout << "Error.\n1. First Class\n2. Second Class" << endl;
    }

    return 0;
}

any suggestions? help? greatly appreciated.

Recommended Answers

All 7 Replies

Well it was suggested in half a dozen places that you should use code tags.
But you ignored all of them, so really what would be the point in spending any more effort on a 7th or 8th attempt.

I didnt quite understand that. Are you saying that I should refer to other threads for help? code tags? 7th 8th attempt? ...

Use pencil and paper to work out your logic before trying to write the code. It might look something like this:

assume:
a seat equals an element of the array
if value of an element in the array is zero, then seat is available
logic:
if(decision == 1)
  if no first class seats available
    display message
  else
    display message--the following seats are open
    loop through first five seats of plane 
      if value of current element of plane is zero
         display result of current index plus 1 
      use a loop to allow user selection of available seats
      loop until valid selection made or user gives up
         display request for selection
         if valid selection
           if selected seat is availble
             change value of that seat to some value other than zero
           else 
             display message that seat is already taken
        else 
           display message that seat is not part of first class

I have been working on a similar project, but am stalled in my attempts to test my program. I have a syntax error inthe main part of my program but have been unable to find it. I have listed the error message below.....

error C2059: syntax error : 'return'

I am at my whits end and would be gratefull for any help or hints in finding my error .

// Program: First Economy Air,  Automated Seat Reservation Program 
// This is a menu driven program that assigns seats in a 10 seat 
//airplane, then prints out a boarding pass then a seating chart
// seats 1-5 are first class and 6-10 are economy
// Amy Higgins


#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

//function prototypes

void showMenu ();		        // Holds menu choices		
void printSeatingChart (int [], int);   // Prints to screen Array
void firstClassTicket (int [], int);      // Used to assign first class seats if availible
void economyTicket (int [], int);      // Used to assign economy seats if availible


int main()
{
    const int SEATS = 10;           // Seating capacity of airplane
    int airplane[SEATS] = {0};   // Airplane array, used to keep 
                                                // track of open and occupied seats
    int firstClass;	            //  holds the seat number reserved (1-5)
   int economy;	           // holds the seat number reserved (6-10)
    nt choice;	                // To hold a menu choice
	

   
   do
   {
         // Display the menu and get the user's choice.

          showMenu();
          cin >> choice;
      
      // Validate the menu selection.

       while (choice < 1 || choice > 3)
               {
                  cout << "Please enter 1, 2, or 3: ";
                   cin >> choice;
                }
        if (choice >= 1 || choice <= 3)            
            {
	        switch (choice)
                               {
                               case 1:  firstClassTicket(airplane, SEATS);
                                                 break;
                                case 2: economyTicket(airplane, SEATS);
                                                break;
                                case 3:  printSeatingChart(airplane, SEATS);
		                break;
                                }
            }
      }  
[B]return 0;[/B]
}

//**************************************************
// Definition of function showMenu which displays the menu.       *
//*************************************=************

void showMenu()
{
   cout << "\n\t\tWelcom to First Economy Air\n\n";
   cout<<"======================================\n";
   cout<<" Please select an option from the menu \n";
   cout<< "below."<<endl<<endl;

   cout << "1. First Class Ticket\n";
   cout << "2. Economy Ticket\n";
   cout << "3. Exit\n\n";
   cout << "Enter your choice: ";
}
//*******************************************
// Definition of function printSeatingChart                       *
//********************************************

void printSeatingChart (int array [], int size)
{

cout<< "print seat chart, exit."<<endl;
         for(int i = 0; i < size; i++)       // Print contents of array
              {
	cout<< array[i]<<endl;
              }
}

//*****************************************
// Definition of function firstClassTicket                        *
//******************************************

void firstClassTicket (int array [], int size)
{
            // this is just a test to see if this function 
          //can read and return array values
 
     cout<< "you have purchased a First class ticket."<<endl;
	           for(int i = 0; i < size; i++)
                                 {
	                    cout<< array[i]<<endl;
                                  }
}

//*******************************************
// Definition of function economyTicket                           *
//*******************************************

void economyTicket (int array [], int size)	
{
	// this is just a test to see if this function 
               //can read and return array values

	cout<< "you have purchased a Economy ticket."<<endl;
		for(int i = 0; i < size; i++)
                                       {
	                            cout<< array[i]<<endl;
                                        }
}

Firstly, please don't hijack others threads...start your own in future. Your syntax error is the fact that you have a do..while loop definded as follows

do{
    //somecode
}

with no while statement

do{
    //somecode
}while(somecondition);

Chris

I'm sorry , hijacking the thread was not my intent. In some of the threads I read earlier the repliers complained of people starting multiple threads on the same subject. In an attempt to avoid one blunder I have made another. I'll reread the tutorial on posting threads before I make another post.
Thank you for your quick answer. I know what i need to change now. Thank you for your help once again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.