All pastes #756966 Raw Edit

plane seats

public cpp v1 · immutable
#756966 ·published 2007-10-31 21:09 UTC
rendered paste body
#include <iostream>using namespace std;int checkSeats(int, int[][]);int main(){	int seats[2][5], numSelection, seatUsed;	char selection;	do{		cout<<"first class(1) or economy class(2)? ";		cin>>numSelection;	}while(numSelection != 1 && numSelection != 2);	if (numSelection == 1){		seatUsed = checkSeats(0, seats[][]);		if (seatUsed != 0)			cout<<"you have been placed in first class seat "<<seatUsed<<"thanks for flying!"<<endl;		else if (seatUsed == 0){			selection = 'l';			do{				cout<<"all first class seats are taken! would you like an economy class seat? (y/n) ";				cin>>selection;			}while (selection != 'y' && selection != 'n');			if (selection == 'y'){				seatUsed = checkSeats(1, seats[][]);				if (seatUsed != 0)					cout<<"you have been placed in economy class seat "<<seatUsed<<"thanks for flying!"<<endl;				else if (seatUsed == 0)					cout<<"sorry, the plane is full!"<<endl;			}		}//end seats used else if	}//end selection 1	return EXIT_SUCCESS;}int checkSeats(int whichClass, int seats[][]){		int seatFound=0;		for (int check=0; check<=4; check++){			if (seats[whichClass][check]==0){				seats[whichClass][check] = 1;				seatFound = check+1; // store the seat assigned in a variable, add one so its not seat 0				check = 10; // end loop immediately			}		}	return seatFound; //if no seat is found seatFound will return 0}