Array C++ Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 2
Reputation: watersnow14 is an unknown quantity at this point 
Solved Threads: 0
watersnow14 watersnow14 is offline Offline
Newbie Poster

Array C++ Help

 
0
  #1
Nov 25th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Array C++ Help

 
0
  #2
Nov 25th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: watersnow14 is an unknown quantity at this point 
Solved Threads: 0
watersnow14 watersnow14 is offline Offline
Newbie Poster

Re: Array C++ Help

 
0
  #3
Nov 25th, 2008
I didnt quite understand that. Are you saying that I should refer to other threads for help? code tags? 7th 8th attempt? ...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 81
Reputation: minas1 is an unknown quantity at this point 
Solved Threads: 8
minas1's Avatar
minas1 minas1 is offline Offline
Junior Poster in Training

Re: Array C++ Help

 
0
  #4
Nov 25th, 2008
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,749
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 283
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Array C++ Help

 
0
  #5
Nov 25th, 2008
Use pencil and paper to work out your logic before trying to write the code. It might look something like this:
  1. assume:
  2. a seat equals an element of the array
  3. if value of an element in the array is zero, then seat is available
  4. logic:
  5. if(decision == 1)
  6. if no first class seats available
  7. display message
  8. else
  9. display message--the following seats are open
  10. loop through first five seats of plane
  11. if value of current element of plane is zero
  12. display result of current index plus 1
  13. use a loop to allow user selection of available seats
  14. loop until valid selection made or user gives up
  15. display request for selection
  16. if valid selection
  17. if selected seat is availble
  18. change value of that seat to some value other than zero
  19. else
  20. display message that seat is already taken
  21. else
  22. display message that seat is not part of first class
Last edited by Lerner; Nov 25th, 2008 at 11:57 am.
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: AmyH2008 is an unknown quantity at this point 
Solved Threads: 0
AmyH2008 AmyH2008 is offline Offline
Newbie Poster

Re: Array C++ Help I can't find error C2059!

 
0
  #6
Dec 6th, 2008
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;
                                }
            }
      }  
return 0;
}

//**************************************************
// 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;
                                        }
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Array C++ Help

 
0
  #7
Dec 6th, 2008
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

  1. do{
  2. //somecode
  3. }
with no while statement
do{
    //somecode
}while(somecondition);

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: AmyH2008 is an unknown quantity at this point 
Solved Threads: 0
AmyH2008 AmyH2008 is offline Offline
Newbie Poster

Re: Array C++ Help

 
0
  #8
Dec 6th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC