Program Error

ok, I have a Program that im trying to get working.

Im trying to update a person Name. but when i enter their name the program goes off in a continuous Loop


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
        if (choice == 2) // Updates Record..
            
            
		{
              fstream myFile("AirLine.text", ios::in | ios::out | ios::app );
           
           
            merge_sort(0,N_PASSENGER-1);
            
            cout << "\n\t Enter the Seat Number:";
            cin >> key;
            
            k=binarySearch(stArray, 0, N_PASSENGER, key);
            if(k>=0) 
                
                
                cout << " Enter Passengers Name:";
            cin >> stArray[i].Newname;
            
            
            
            for (i=0; i<N_PASSENGER; i++)
            {
                if (stArray[i].seat_number == key)
                    
                    stArray[i].name = stArray[i].Newname;
            }
               
            
            myFile.close();
		}
        
        
        
what type is stArray[i].Newname?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using namespace std;

int binarySearch(struct  passenger s[], int first, int upto, int key);
void merge_sort(int,int,int);
void merge (int low, int mid, int high);
void merge_sort(int low, int high);




struct passenger

{ 
    int seat_number;
    string name;
    string Newname;
    string connecting_flight;
};

int N_PASSENGER;
struct passenger stArray[30];
I change the whole update Round to make it that bit easy.


but getting problems with Location.. can some one help me with this. Im trying to update a name thats inside a text File, once i update the name it should then Replace the Name inside the Text file with the New name i just entered.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
if (choice == 2) // Updates Record..
            
            
		{
              fstream myFile("AirLine.text", ios::in | ios::out | ios::app );
           
           cout << "Enter Passenger Seat Number:";
           cin >> key
                 
            int location = 0; 
                    
           location = (stArray[i].seat_number -1)* sizeof(passenger);  
           myFile.seekp(location);
           
           
        
           cout << " Enter Passengers New Name:";
           cin >> stArray[i].Newname;
           myFile << stArray[i].Newname;
            
            
            for (i=0; i<N_PASSENGER; i++)
            {
                if (stArray[i].seat_number == key)
                    
                    stArray[i].name = stArray[i].Newname;
            }
            cout << "Passengers name is now " << stArray[i].Newname;
            
      
                    
                 
            myFile.close();


Last edited on
Topic archived. No new replies allowed.