while loop issue, putting the finishing touches on program.

The current (and final) problem is this.
When I enter "Q" the first time because I don't want to search everything is fine and it just quits and goes to the next function. BUT when I enter a city that is found and then try to quit, it doesn't work. It will just read back " not found".
It always cuts off the first letter. If I searched for cplusplus.com it would read back "plusplus.com not found". It's not quitting after I find a city though. What should I change?
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
void findCityData (string city[], double budget[], double revenue[], int NumCities) 
{  
    string target; 
    int pos; 
     
    cout << "Enter the name of the city or Q to quit:"; 
    getline (cin,target); 



     while(target != "Q" && target != "q") 
    { 
        pos = searchFunction (city, NumCities, target); 
        if (pos == -1) 
        { 
            cout << target << " not found." << endl; 
            findCityData (city, budget, revenue, NumCities); 

        } 
        cout << city[pos] << " has a budget of " << budget[pos] << " and revenue totaling " << revenue[pos] << endl; 
        cout << "Enter the name of the city or Q to quit:"; 
        cin.ignore(); 
        getline (cin,target); 
          
         
             

    } 

what do you think that cin.ignore is ignoring?
I really don't know. I commented it and it appears to be working in Unix now. We have a set number of things we're supposed to input and after I input them and press "Q" to quit, I get a Bus error. I'm not even sure what that is.
Last edited on
Topic archived. No new replies allowed.