airplane again

This is a discussion on airplane again within the C++ Programming forums, part of the General Programming Boards category; i have a plane w/10 seats 5 1st class 5 economy and when one is full u ask if it ...

  1. #1
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Question airplane again

    i have a plane w/10 seats 5 1st class 5 economy and when one is full u ask if it is alright to putin the oppoiste one and if not you say next flight in 3 hrs and i dont know what happened w/this thing
    this thing is driving me nuts
    help?
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    14
    Try to take a deep breath between each sentance and explain your problem again.
    Hopefully this will help us understand whatever your problem is.

    /Laos

  3. #3
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45
    My program is a plane w/ten seats and 5 r 1st class 5 r economy
    u choose 1 for 1st and 2 for economy and when all five in one of the sections is full u ask the user to say yes to whether or not it is okay to put them in the other section my problem is that when all of the spaces is full in one of the classes it totally ends w/o asking to be put in the other section or not and i cant figure out this stupid thing i think i have a few other bugs in this thing like when i did have my question to go to another class it would reassign an assigned seat and econ would wind up in a infinite loop after the ? i fixed the code a little could anyone possibly help me

    fixed program:
    Attached Files Attached Files

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Nasty code you had there edshaft, normally I don't have any problem following the logic but your program gave me fits
    Anyway, it works now. Let me know if you have any more questions.
    Code:
    #include <iostream>
    using namespace std;
    
    int first(int& i, int& j, int flagFirst, int flagEcon);
    int econ(int& i, int& j, int flagFirst, int flagEcon);
    
    int main()
    {
    	int assign, i = 1, j = 1, flagFirst = 0, flagEcon = 0;
    
    	while(flagFirst != 1 && flagEcon != 1){
    		cout<<"Please type 1 for First Class\n";
    		cout<<"Please type 2 for Economy\n";
    		cin>>assign;
    
    		if (assign == 1){
    			first(i, j, flagFirst, flagEcon);
    		}
    		else{
    			econ(i, j, flagFirst, flagEcon);
    		}
    	}
    	return 0;
    }
    
    int first(int& i, int& j, int flagFirst, int flagEcon){
    	char non;
    	if(flagFirst == 1 && flagEcon == 1){
    		cout<<"All seats are full"<<endl;
    		exit(0);
    	}
    	if(i > 5){
    		flagFirst = 1;
    		cout<<"First class is full. Is it all right to place you in nonsmoking?(y/n)\n"<<flush;
    		cin>> non;
    		if(non=='y'|| non == 'Y'){
    			econ(i, j, flagFirst, flagEcon);
    		}
    		else
    			cout<<"Next flight in three hours\n";
    	}
    	else{
    		flagFirst = 0;
    		cout<<"You are in seat "<<i++<<" in first class\n";
    	}
    	return 0;
    }
    
    int econ(int& i, int& j, int flagFirst, int flagEcon){
    	char non;
    	if(flagFirst == 1 && flagEcon == 1){
    		cout<<"All seats are full"<<endl;
    		exit(0);
    	}
    	if(j > 5){
    		flagEcon = 1;
    		cout<<"Economy is full. Is it all right to place you in smoking?(y/n)\n"<<flush;
    		cin>> non;
    		if(non=='y'|| non == 'Y'){
    			first(i, j, flagFirst, flagEcon);
    		}
    		else
    			cout<<"Next flight in three hours\n";
    	}
    	else{
    	    flagEcon = 0;
    		cout<<"You are in seat "<<j++<<" in economy\n";
    	}
    	return 0;	
    }
    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Smile

    thanx man u have been a real big help

  6. #6
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Thumbs down

    well the code works but i actually need it to work with one array instead of the flagfirst and flagecon you used
    the array is seat[10]
    i tried to fix it but im screwed up once again and if anyone helps that would be wonderful
    the despriction of how it works is the same it is just that i need it to work w/that array
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Airplane fuel-efficiency
    By itsme86 in forum C Programming
    Replies: 6
    Last Post: 02-01-2005, 10:05 AM
  2. Airplane game
    By JoshG in forum Game Programming
    Replies: 4
    Last Post: 06-08-2002, 04:47 PM
  3. member functions having the class's name
    By Linette in forum C++ Programming
    Replies: 8
    Last Post: 01-30-2002, 11:04 AM
  4. I wanna build myself an airplane
    By Series X4 1.0 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 01-14-2002, 12:43 PM
  5. I got this in my email.
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 10:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21