Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

work in progress but errors!

[blue] I can't seem to get past my errors and figure out how to tell if the flight is full. Here is my work in progress. Thanks in advance for your help. I'll get C++ if it kills me...lol tho it just might :) [/blue]


[code]
#include

using std::cout;
using std::cin;
using std::endl;


int seats[ 10 ] = { 0 }; //seat array of 10
int answer = 0;
int passenger = 0;
int mpassengers = 10; //max amt seats
int p = 0;
int fcseats = 0; //first class seats
int eseats = 5; //economy seats



{

int main ()
{




passenger++; //passenger counter

while (passenger <= mpassengers); //passengers less than 10


cout<< "Please hit 1 for First Class or 2 for Economy
";
cin>> answer; //prompt for input


if(answer == 1) //1 for first class

{
if(fcseats <=5 )


seats[fcseats] = ++fcseats;
}

cout<< "Your seat number is: "<<seats[fcseats] << "in First Class"<<endl;

//code if fc is full


cout<< "First class is full. Please choose 2 for Economy." <<endl;

if(answer == 2) //2 for economy class

{
if(eseats <=10 )



seats[eseats] = ++eseats;
}

cout<< "Your seat number is: "<<seats[eseats] << "in Economy"<<endl;

//code if economy is full

cout<< "Economy is full. Please choose 1 for First Class." <<endl;


for (p = 0; p < mpassengers; p++)
seats[p] = 0; //set seat array to 0


cout << "Flight is booked. Next flight leaves in 3 hours."


return 0;



[/code]

Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    Check the braces -- there is an extraneous brace before main() and there is not one at the end of the last function, after the return. Finally you need a semicolon at the end of the line just before the last return.


  • lilblondielilblondie Member Posts: 7
    [b][red]This message was edited by lilblondie at 2004-8-18 18:32:58[/red][/b][hr]
    [blue] Okay, okay....I totally rewrote the program but I dont know how to check seat array space or add to the array??? [/blue]

    [code]
    #include



    main()
    {
    int seats[10];
    int choice;
    int fcarray[5] = {0};
    int earray[5] = {0};
    int passenger;
    int i = 0;
    char yesno;

    while( passenger < 10 )




    {
    cout<< "Please Choose 1 for First Class
    ";
    cout<< "Please Choose 2 for Economy Class
    ";
    cin>> choice; //prompt for input

    if(choice == 1)
    {

    cout << "You chose First Class" << endl;

    if( xxx && xxx ) //check seat array space and if range is available first class
    {
    fcarray[i]++; // add 1 to array assign seat
    passenger++; // increment passenger
    }
    else if( xxx && xxx ) //check if its full and other section seat available
    {
    cout << "That section is full. Do you want a seat in another section? Y or N " << endl; // indicate section is full
    // ask if they want a seat in the other section Y or N
    cin>> yesno; //prompt for input

    if( yesno == 'Y') //check the responce for Y
    {
    earray[i]++; //add 1 to array to assign a seat in the other class
    passenger++; // increment passenger

    }
    else
    {
    cout << "The next flight leaves in 3 hours" << endl; // indicates the next flight leaves in 3 hours if they chose N
    }
    } //closing else if bracket
    else
    {
    cout << "The next flight leaves in 3 hours" << endl; // indicate the next flight leaves


    }
    } //closing if choice bracket


    // {

    if(choice == 2)
    {

    << "You chose Economy Class" << endl;
    if( xxx && xxx ) //check seat array space and if range is available first class
    {
    fcarray[i]++; // add 1 to array assign seat
    passenger++; // increment passenger
    }
    else if( xxx && xxx ) //check if its full and other section seat available
    {
    cout << "That section is full. Do you want a seat in another section? Y or N " << endl;// indicate section is full
    // ask if they want a seat in the other section Y or N
    cin>> yesno; //prompt for input

    if( yesno == 'Y') //check the responce for Y
    {
    fcarray[]++; //add 1 to array to assign a seat in the other class
    passenger++; // increment passenger
    }
    else
    {
    cout << "The next flight leaves in 3 hours" << endl; // indicates the next flight leaves in 3 hours if they chose N
    }
    } //closing else if bracket
    else
    {
    cout << "The next flight leaves in 3 hours" << endl; // indicate the next flight leaves rs

    }
    } //closing if choice bracket


    } //end of else for choice being 2




    } // closing while loop bracket

    return 0;
    }



    [/code]




  • pseudocoderpseudocoder Member Posts: 701 ✭✭✭
    : [b][red]This message was edited by lilblondie at 2004-8-18 18:32:58[/red][/b][hr]
    : [blue] Okay, okay....I totally rewrote the program but I dont know how to check seat array space or add to the array??? [/blue]

    I'm not sure what you're doing with all of the arrays, but if you wish to test for seat availability, then it would be easy to prompt for the seat directly.

    [code]
    cout << "Choose 1....";
    cin >> choice;

    cout << (choice == 1 ? "Enter a seat number (1-range): " : "Enter a seat number (range - max): ";
    cin >> seatnum;

    // test that seatnum is in the correct class, and in the correct bounds of your array

    if(seats[seatnum - 1] == 0)
    {
    seats[seatnum - 1] = 1;
    passenger++;
    }
    else
    // no seats left in class range
    [/code]

    You've got initialization errors too. passenger needs to be initialized. It may be a bit easier on you if you used a 2D array for the seats since you can use choice for the dimension index.

    [code]
    int seats[2][5] = { { 0 } , { 0 } };

    /* or init seats before using

    for(int i=0; i < 5; i++)
    for(int j=0; j < 5; j++)
    seats[i][j] = 0;
    */

    cin >> choice;

    // validate choice

    switch(choice - 1)
    {
    case 0: //working with seats[0][0-4];
    break;

    case 1: // working with seats[1][0-4];
    break;
    }[/code]



    :
    : [code]
    : #include
    :
    :
    :
    : main()
    : {
    : int seats[10];
    : int choice;
    : int fcarray[5] = {0};
    : int earray[5] = {0};
    : int passenger;
    : int i = 0;
    : char yesno;
    :
    : while( passenger < 10 )
    :
    :
    :
    :
    : {
    : cout<< "Please Choose 1 for First Class
    ";
    : cout<< "Please Choose 2 for Economy Class
    ";
    : cin>> choice; //prompt for input
    :
    : if(choice == 1)
    : {
    :
    : cout << "You chose First Class" << endl;
    :
    : if( xxx && xxx ) //check seat array space and if range is available first class
    : {
    : fcarray[i]++; // add 1 to array assign seat
    : passenger++; // increment passenger
    : }
    : else if( xxx && xxx ) //check if its full and other section seat available
    : {
    : cout << "That section is full. Do you want a seat in another section? Y or N " << endl; // indicate section is full
    : // ask if they want a seat in the other section Y or N
    : cin>> yesno; //prompt for input
    :
    : if( yesno == 'Y') //check the responce for Y
    : {
    : earray[i]++; //add 1 to array to assign a seat in the other class
    : passenger++; // increment passenger
    :
    : }
    : else
    : {
    : cout << "The next flight leaves in 3 hours" << endl; // indicates the next flight leaves in 3 hours if they chose N
    : }
    : } //closing else if bracket
    : else
    : {
    : cout << "The next flight leaves in 3 hours" << endl; // indicate the next flight leaves
    :
    :
    : }
    : } //closing if choice bracket
    :
    :
    : // {
    :
    : if(choice == 2)
    : {
    :
    : << "You chose Economy Class" << endl;
    : if( xxx && xxx ) //check seat array space and if range is available first class
    : {
    : fcarray[i]++; // add 1 to array assign seat
    : passenger++; // increment passenger
    : }
    : else if( xxx && xxx ) //check if its full and other section seat available
    : {
    : cout << "That section is full. Do you want a seat in another section? Y or N " << endl;// indicate section is full
    : // ask if they want a seat in the other section Y or N
    : cin>> yesno; //prompt for input
    :
    : if( yesno == 'Y') //check the responce for Y
    : {
    : fcarray[]++; //add 1 to array to assign a seat in the other class
    : passenger++; // increment passenger
    : }
    : else
    : {
    : cout << "The next flight leaves in 3 hours" << endl; // indicates the next flight leaves in 3 hours if they chose N
    : }
    : } //closing else if bracket
    : else
    : {
    : cout << "The next flight leaves in 3 hours" << endl; // indicate the next flight leaves rs
    :
    : }
    : } //closing if choice bracket
    :
    :
    : } //end of else for choice being 2
    :
    :
    :
    :
    : } // closing while loop bracket
    :
    : return 0;
    : }
    :
    :
    :
    : [/code]
    :
    :
    :
    :
    :
Sign In or Register to comment.