Help!! Debugging issue

Can I get a set of fresh eye on this bit of code... the getline function is not letting me do the user input for the search. do I have it set up wrong?
Please check out the lookupTaxes() function. everything else is working great but that.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

//Globals
int SIZE = 7;
string Add[7] = {"151 Acorn", "161 Acorn", "200 Main", "500 Arcade", "161 Acorn", "120 Xenia", "200 Acorn" };
int Tax[7] = {500, 1500, 15000, 25000, 6000, 1000, 20000};


//Function Prototypes
void displayMenu();
void displayAllData();
void lookupTaxes();
void displaySorted();
int Largest();



int main() {
    
    int results, option;
    
    while (true) {
        displayMenu();
        cout<<"Please make your selection: ";
        cin>> option;
        cout<<endl;
        
        switch (option) {
            case 1:
                displayAllData();
                break;
            case 2:
                 lookupTaxes();
                break;
            case 3:
                displaySorted();
                break;
            case 4:
                results = Largest();
                if (results ==  !-1) {
                   cout<<"error please try again";
                
                }
                else
                    
                    cout<<"Address With Highest Taxes Due: "<< Add[results]<<"\n";
                    cout<<"Taxes due: $"<<Tax[results]<<"\n";
                    cout<<endl;
                break;
                
            default:
                
                break;
        }
      
        if(option== 5)
            break;
        
    }
    
     cout<<"Thank you, Good-Bye.........\n";
    
    return 0;
}

void displayMenu(){

    cout<<"Menu Of Options: \n";
    cout<<"1.Display All Tax Data. \n";
    cout<<"2.Look Up A Certain Address For Specific Tax Data. \n";
    cout<<"3.Sort Tax Data in Accending Order. \n";
    cout<<"4.Display Property with Highest Taxes Due. \n";
    cout<<"5.To Exit\n";

}
void displayAllData(){

    cout<<"All Tax Data: \n";
    
    cout<<"Address"<<setw(22)<<"Taxes\n";
    cout<<"......................................\n";
    
    for (int i = 0; i < SIZE; i++) {
        cout<<Add[i]<<"\t\t\t\t$"<<Tax[i]<<"\n";
    }
    cout<<endl;
    
}
void lookupTaxes(){
    string addressSelect;
    cout<<"Enter Address to search:\n";
    getline(cin, addressSelect);
    
    
    int i;
    bool notFound=true;
    for(i=0;i<SIZE;i++)
    {
        if(addressSelect == Add[i])
        {
            cout<< fixed <<showpoint <<setprecision(2);
            cout<<"Tax details\n";
            cout<<"Address: "<<Add[i]<<endl;
            cout<<"Taxes: $"<<Tax[i]<<endl;
            notFound=false;
        }
    }
    if(notFound)
    {
        cout<<"Tax details not found\n\n";
        
    }

}
void displaySorted(){

    int startscan,minIndex;
    string tempID;
    double minVal;
    
    for (startscan = 0;startscan < (SIZE -1); startscan++) {
        minIndex = startscan;
        minVal = Tax[startscan];
        tempID = Add[startscan];
        
        for (int index = startscan +1; index < SIZE; index++) {
            if (Tax[index] < minVal) {
                minVal = Tax[index];
                tempID = Add[index];
                minIndex = index;
            }
        }
        Tax[minIndex]= Tax[startscan];
        Add[minIndex] = Add[startscan];
        Tax[startscan] = minVal;
        Add[startscan] = tempID;
    }
    cout<<"Address"<<setw(22)<<"Taxes\n";
    cout<<"......................................\n";
    for (int i = 0; i < SIZE; i++) {
        cout<<Add[i]<<"\t\t\t\t$"<<Tax[i]<<"\n";
    }
    cout<<endl;
}
int Largest(){
    int index=0, position = -1;
    double highest;
    bool found = false;
    
    highest = Tax[0];
    
    for (int i=0; i <SIZE; i++) {
        if(Tax[i] > highest)
            highest = Tax[i];
    }
    
    while (index < SIZE && !found) {
        if (Tax[index] == highest) {
            found = true;
            position = index;
        }
        index++;
        
    }
return position;

}



You just need to include a line before the getline function is called

cin.ignore();

Because when the user inputs an enter in the cin statement. That enter is stored in the buffer and when the getline function reads it, it terminates the call.
Last edited on
Topic archived. No new replies allowed.