abnormal program termination

This is a discussion on abnormal program termination within the C++ Programming forums, part of the General Programming Boards category; Any suggestions as to what would cause my program to run properly until it hops out of while loops to ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    17

    abnormal program termination

    Any suggestions as to what would cause my program to run properly until it hops out of while loops to print out a closing statement??? I listed the read in file also?? Thanks a bunch!!

    Bashemin.in reads:

    aVAX785
    aPDP11
    aIBM360
    aMTHCSC
    dPDP11
    p
    aMAC512
    dVAX785
    aPI314
    aCSB-1
    dCSB-1
    dIBM360
    p
    aPDP11
    a257ADT
    dMAC512



    Code:
    
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <stack>
    #include<iomanip>
    
    using namespace std;
    
    int main()
    {
    	stack<string> parkinglot;
    	stack<string> alley;
    	stack<string> hold;
    	/*Stack parkinglot; //Parking lot
    	Stack alley; //Alley
    	Stack hold; //Place to store while running print*/
    
    
    	string plate; //License plate info
        char c;		//Used for Printing pause to screen
    	char firstchar;  //String in the in file
    	string s;		//Hlds each car data
    	int f = 0;// Counter to determine if lot is full
    	int i = 0;//Keeps track of moved cars
    	string filename;//Bashemin
    	
    	cout << "            Welcome to the Bashemin Parking Lot." << endl << endl;
    	cout << "\nEnter filename to process (bashemin.in used for sample data): ";	
    	cin >> filename;
    
    	ifstream cinf(filename.c_str()); //get data
    
    	if (!cinf){          //error message
    		cout << "Cannot open file " << filename << endl;
    		exit(1);
    	}
    
    
    	while (getline(cinf,s,'\n')){
    		firstchar = s[0];
    		plate = s.substr(1);
    	
    		
    	
            //if car arrives and lot is full do:
    		if (firstchar== 'a' && f==5){
    			cout << "Lot is full you may not park here!!"<< endl;
    		}
    		//if car arrives and lot isn't full do:
    		if(firstchar == 'a' && f!= 5) {     
    			parkinglot.push(plate);  
    			cout<< "Car "<< plate <<" arrived and parked."<<endl;  
    			f ++;
    
    		}
    
    		//if car is departing do:
    		if (firstchar == 'd'){	
    			int i=0;			
    				while (!parkinglot.empty() && parkinglot.top() != plate ){					
    					alley.push(parkinglot.top());
    					parkinglot.pop();
    					i++;
    					
    					//car not found in lot do
    					if(parkinglot.empty() && f==5){
    					cout << "Car " << plate << " not in lot to depart." <<endl;				
    					}				
    				
    				}
    
    		
    				//car found, decrease lot count				
    				if (!parkinglot.empty() && parkinglot.top() == plate){
    					f--;
    					cout << "Car " << plate << " departing;  ";
    					cout << i << " cars moved to get out." << endl;
    					parkinglot.pop();
    					i=0;					
    				}	      
    			}		
    		
    			while (!alley.empty()){
    				parkinglot.push(alley.top());
    				alley.pop();
    			
    			}
    	
    	//Print cars in parking lot:
    		if (firstchar == 'p'){
    		cout <<"Cars parked in Bashemin Lot are:\n";
    			while (!parkinglot.empty()){
    				cout << parkinglot.top() << endl;
    				alley.push(parkinglot.top());
    				parkinglot.pop();
    			}
    
    			while(!alley.empty()){
    				parkinglot.push(alley.top());
    				alley.pop();
    			}
    		
    		}
    	
    	
    	}
    	
    	
    
    	//tow cars left in lot after data flow is done
    	cout << "Bashemin lot is closing and the following cars will be towed." << endl;
    
    	while (!parkinglot.empty()){		
    		cout << parkinglot.top() << endl;
    		alley.push(parkinglot.top());
    		parkinglot.pop();
    	}
    
    	return 0;
    	}
    Last edited by Smiley0101; 03-02-2003 at 04:04 PM.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    17
    So sorry- thought I had a slash in the end code box!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Abnormal program termination
    By Kayoss in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2006, 03:29 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  3. quick termination of program
    By jobolikescake in forum C Programming
    Replies: 7
    Last Post: 01-20-2002, 09:59 PM
  4. abnormal program termination
    By ProLin in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2002, 08:56 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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