Thread: help!!!!!

  1. #1
    Tetra
    Guest

    Unhappy help!!!!!

    i am supposed to write a program that will assign seats on a ten seat plane. dont worry, im not asking you to write code for me im getting a little better at this but my teacher still sucks... so here is what i have.

    btw. the program asks the person to pick a number , ( 1 for first class and 2 for seoncd.) im supposed to use arrays.... so..this is what i have but it doesnt work well... any help would be appreciated emensly.


    Code:
    #include <iostream>
    
    using std::cout; 
    using std::cin;
    using std::endl;
    
    int main ()
    
    { 
    
     int arrayf[5];
    
     int arrays[5];
    
     int num;
    
     int i = 0;
    
     cout<< "Pick a class, 1 for first  and 2 for second.";
     cin>>num;
    
     if (num== 1)
    
     for (int i = 0;i <=arrayf[5];i++)
     
    
     cout<<" Your seat is in " <<num<<"st Class, and your seat number is "<<arrayf[i]<<endl;
    
    
     return 0;
    
     }

    when i compile this it runs forever, so i couldnt get the second class done... please help!!!

    Code tags added by Hammer

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Your problem lies here

    Code:
    for (int i = 0;i <=arrayf[5];i++)
    The array arrayf is uninitialized and arrays are zero-based. This means that you can only use arrayf[0],arrayf[1]...arrayf[4]. They must contain values before you can use them.

  3. #3
    tetra
    Guest

    ooo trickier than i thought,

    how do i assigne values to them? im exremely new to arrays and my teacher doesnt teach he just hands us roblems and plays counter strike i have no clue where to go from here on

  4. #4
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Code:
    arrayf[0] = 1;
    arrayf[1] = 2;
    and so on.

    You initialice int i twice, take a look at that. I can't see why you use the for loop . It's probably just me. You sure you don't want to use rand()?

    Hope this helps
    Last edited by -=SoKrA=-; 11-03-2002 at 11:18 AM.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  5. #5
    tetra
    Guest

    arrays...

    i realy dont get them the tutorial here is kindashady for what i need to do, the plane assignment, i dont know where to start... ugh i really like ot program but i just dont get it, too bad i was jipped with a suckie teacher.

  6. #6
    C++ImDeadagain
    Guest
    I did this program a few days ago....here it is...the complete program......check if it works.....

    Code:
    //air
    
    #include <iostream.h>
    
    int main()
    {
    	int plane[11]={0};
    	int choice;
    	int seatFound =1;
    	int Firstclass =1;
    	int Economy =6;
    	int people =1;
    	
    	cout<< "Please type 1 for \"First Class\"" << endl;
    	cout<< "Please type 2 for \"Economy\"" << endl;
    	cin>> choice;
    
    	while (choice != -1)
    	{
    		if(choice==1) 
    		{
    			seatFound= 0;
    			choice=1;
    			while (choice<6)
    			{
    				if(plane[choice]<1 && Firstclass <=5) 
    				{
    					seatFound=choice;
    					plane[choice] =1;//put person in seat
    					choice=33;//exit loop
    				}
    				else
    					choice ++;
    					people++;
    			}
    			if(seatFound>0)//test if seat is found
    			{
    				cout<<"Boarding Pass"<<endl;
    				cout<<"-First Class-"<<endl;
    				cout<<"Seat#" << seatFound<<endl;
    			}
    			else
    			{
    				cout << "Do you want a seat in economy? " << endl;
    				cout << "\n1 = yes , 2 = no : ";
    				cin >> choice;
    				if ( choice == 2 )
    				{
    					seatFound=0;
    					choice=2;
    					while(plane[choice]<11)
    					{
    						if(plane[choice] > 0 && Economy <= 10 )
    						{
    							plane[choice]=2; // put someone in the seat
    							seatFound=choice;
    							choice=33;
    						}
    					else 
    						choice++;
    						people++;
    					}
    		
    					if(seatFound>0) //test if seat is found
    					{
    						cout<<"Boarding Pass"<<endl;
    						cout<<"Economy Class"<<endl;
    						cout<<"Seat#" << seatFound << endl;
    					}
    				}
    				else
    				{
    					cout << "Next flight leaves in three hours..." << endl;
    				}
    			}
    	}
    		else //economy class
    		{
    			seatFound=0;
    			choice=6;
    			while(plane[choice]<11)
    			{
    				if(plane[choice] < 1)
    				{
    					plane[choice]=1; // put someone in the seat
    					seatFound=choice;
    					choice =2;
    				}
    				else 
    					choice++;
    					people++;
    			}
    		
    			if(seatFound>0) //test if seat is found
    			{
    				cout<<"Boarding Pass"<<endl;
    				cout<<"Economy Class"<<endl;
    				cout<<"Seat#" << seatFound << endl;
    			}
    			else
    			{
    				cout << "Next flight leaves in three hours..." << endl;
    			}
    		}
    
    		cout<< "Please type 1 for \"First Class\" " << endl;
    		cout<< "Please type 2 for \"Economy\" " << endl;
    	
    		cin>> choice;
    	}
    
    	return 0;
    }
    Code tags added by Hammer

  7. #7
    C++ im dead
    Guest

    Angry

    Many C++ teacher can't teach the subject IMO........I'm having trouble with this function Program.....and everytime I ask the my teacher for some help she tells me to read the book.......

    i hope the Code above helps......or compiles....Im sure it will..

Popular pages Recent additions subscribe to a feed