Can't Find Error

This is a program which takes info from a movie website. The program complies but for some reason when executing, the search function goes into an infinite loop.Can't identify why. Also my wget command doesn't work.

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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <iterator>
#include <functional>

using namespace std;

class Movie
{
    friend istream& operator>>(istream&, const Movie&);
    friend ostream& operator<<(ostream&, const Movie&);
    
    public:
        void setVector(string&, string&, string&, string&, string&, string&, int&);
        void setInfo(string, string, string, string, string, string, int);
        string getTitle(const Movie&);
        string getDirector(const Movie&);
        string getRelDate(const Movie&);
        string getGenre(const Movie&);
        string getCast(const Movie&);
        string getSyn(const Movie&);
        int getRuntime(const Movie&);
    
    //private:
        string title;
        string director;
        string reldate;
        string genre;
        string cast;
        string synopsis;
        int runtime;
};

ostream& operator<<(ostream& out, const Movie& mv)
{
    out << mv.title << "|" << mv.director << "|" << mv.reldate << "|"
        << mv.genre << "|" << mv.cast << "|" << mv.synopsis << "|" << mv.runtime;
    
    return out;    
}

void Movie::setVector(string& t, string& d, string& rdate, string& g, string& c, string& s, int& run)
{
    title = t;
    director = d;
    reldate = rdate;
    genre = g;
    cast = c;
    synopsis = s;
    runtime = run;
}

void Movie::setInfo(string t, string d, string rdate, string g, string c, string s, int run)
{
    title = t;
    director = d;
    reldate = rdate;
    genre = g;
    cast = c;
    synopsis = s;
    runtime = run;
}

string Movie::getTitle(const Movie& rhs)
{
    return title;
}
string Movie::getDirector(const Movie& rhs)
{
    return director;
}
string Movie::getRelDate(const Movie& rhs)
{
    return reldate;
}
string Movie::getGenre(const Movie& rhs)
{
    return genre;
}
string Movie::getCast(const Movie& rhs)
{
    return cast;
}
string Movie::getSyn(const Movie& rhs)
{
    return synopsis;
}
int Movie::getRuntime(const Movie& rhs)
{
    return rhs.runtime;
}
 
Last edited on
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
class Dbase
{
    public:
        void add();
        void remove();
        void search();
        void summary();
        int infile();
        
    private:
        bool compare(const Movie&);
        void outfile();
        Movie mov;
        vector<Movie> m;
        vector<Movie>::iterator it;
};

bool Dbase::compare(const Movie& rhs)
{
    it = m.begin();
    cout << "Checking movie in database.." << endl;
    
    for (int i = 0; i < m.size(); i++)
    {
        
        if ((m[i].title == rhs.title) && (m[i].reldate == rhs.reldate))
        {
            cout << "Movie data found!!" << endl;
            return true;
        }
        it++;
    }
    return false;
}

int Dbase::infile()
{
    ifstream fin;
    string s, z, name;
    string temp[7];
    int i, rt;
    fin.open("movdb.txt");
    if (!fin.good())
    {
       /* cout << "Please enter the website name you want to grab" << endl;
        cin >> name;
        command="wget -q -O filename URL";
        system(command.c_str());
        return get;*/
       return 1; 
    }    
    else
    {
        while (getline(fin, s))
        {
            stringstream ss(s);
            i = 0;
            while (getline(ss, z, '|'))
            {
                temp[i] = z;
                ++i;
            }
            rt = atoi( temp[6].c_str() );
            mov.setVector(temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],rt);
            m.push_back(mov);
        }
        return 0;
    }    
}

/*void Dbase::wCheck(int num)
{
   if(num == 1)
     {
       if(strcmp(("http://www.imdb.com",name.c_str())== 0) 
         cout << "Here: " << endl;
     }
}*/         
void Dbase::outfile()
{
    ofstream fout;
    fout.open("movdb.txt");
    
    if (!fout.good())
        cout << "Output file corrupted!!" << endl;
    else
        for (int i = 0; i < m.size(); i++)
            fout << m[i] << endl;
    
    fout.close();
}
    
void Dbase::add()
{
    
    if (compare(mov) == true)
    {
       cout << "Duplicate data was not added.." << endl; 
    }
    else
    {
        m.push_back(mov);
        cout << "A movie data has been added successfully!!" << endl;
    }
    outfile();
}

void Dbase::remove()
{
    char rmv;
    string a;
    
    cout << "Please enter movie data data that you want to remove.." << endl;
    cin.ignore(1000, '\n');
    cout << "Title: ";
    getline(cin, mov.title);
    cout << "Release Date: ";
    getline(cin, mov.reldate);
    
    if (compare(mov) == true)
    {
        while ((rmv != 'Y') && (rmv !='y') && (rmv != 'N') && (rmv != 'n'))
        {
            cout << "Confirm to remove movie data?? (Y/N): ";
            cin >> rmv;
        }
        if (rmv == 'Y' || rmv == 'y')
        {
            m.erase(it);
        }
    }
    else
        cout << "Movie not found!!" << endl;
}

void Dbase::search()
{
   int opt; string first_v, second_v;
   cout << "Please choose a search option 1.Title 2.Director 3.Release 4.Title & Director 5.Genre 6.Title & Release" << endl;
   cin >> opt;
   
  //Using switch case here to search for individual move details
  while(opt > 0 && opt < 7)
  {
   switch(opt)
    {
     case 1: cout << "Please provide movie title: " <<endl;
             cin >> first_v;
             it = m.begin();
             while(it != m.end())
             {   
               if(first_v == mov.title)
               cout << "The movie is: " << mov.title << endl;
               else
               it++;
             }
             break;
             
    case 2:  cout << "Please provide movie director's name: " <<endl;
             cin >> first_v;
             it = m.begin();
             while(it != m.end()){
             if(first_v == mov.director)
             cout << "The movies directed by this person are: " << mov.title << endl;
             it++;
             }
             break;
             
    case 3:  cout << "Please provide movie release date: " <<endl;
             cin >> first_v;
             it = m.begin();
             while(it != m.end()){
             if(first_v == mov.reldate)
             cout << "The movies with this release date are: " << mov.title << endl;
             it++;
             }
             break;
             
    case 4:  cout << "Please provide movie director's name & title: " <<endl;
             cin >> first_v;
             cin >> second_v;
             it =m.begin();
             while(it != m.end()){
             if(((first_v == mov.director) && (second_v == mov.title))||(first_v == mov.title) && (second_v == mov.director))
             cout << "The movie is: " << mov.title<< endl;
             it++;
             }
             break;
             
    case 5:  cout << "Please provide genre of movie: " <<endl;
             cin >> first_v;
             it = m.begin();
             while(it != m.end()){
             if(first_v == mov.genre)
             cout << "The movies of this genre are: " << mov.title<< endl;
             it++;
             }
             break;
             
    case 6:  cout << "Please provide title of the movie & its release date: " <<endl;
             cin >> first_v;
             cin >> second_v;
             it = m.begin();
             while(it != m.end()){
             if((first_v == mov.title)&&(second_v == mov.reldate)||(first_v == mov.reldate)&&(second_v == mov.title))
             cout << "The movies are: " << mov.title<< endl;
             it++;
             }
             break;
   
   }

 } 
}

void Dbase::summary()
{
    cout << setw(30) << left << "Title" << setw(25) << "Director" << setw(20) << "Release Date"
         << setw(30) << "Casts" << setw(15) << "Genre" << setw(10) << right << "Runtime" << endl;
    
    for (int i = 0; i < m.size(); ++i)
        cout << m[i] << endl;
}

class MovieManager
{
    public:
        MovieManager();
        void mainMenu();
        void optionCase(int);
        
    private:
        int choice;
        Dbase db;
};

MovieManager::MovieManager()
{
    while (choice != 5) 
        mainMenu();
}

void MovieManager::mainMenu()
{
    cout << "===========================" << endl;
    cout << "     Main Menu option:     " << endl;
    cout << "---------------------------" << endl;
    cout << "1. Add" << endl;
    cout << "2. Remove" << endl;
    cout << "3. Search" << endl;
    cout << "4. Summary" << endl;
    cout << "5. Quit" << endl << endl;  
    cout << "Enter your selection: ";
    
    db.infile();
    
    cin >> choice;
    optionCase(choice);

}

void MovieManager::optionCase(int choice)
{
    switch (choice)
    {
        case 1:
            db.add();
            break;
            
        case 2:
            db.remove();
            break;
            
        case 3:
            db.search();
            break;
            
        case 4:
            db.summary();
            break;
        case 5:
            break;
    }
}

int main()
{   
    MovieManager i;
    cout << "I'm done" << endl;
    system("pause");
    return 0;
}
It seems that the variable opt in your search function doesn't change, so when opt is between 0 and 7, it keeps between it, so the loop keeps running.
No that's not the problem. It was the while loop. But now I have modified the code & my search is too messy. Anyone can suggest a better way to do partial search & how to implement update in add function. Also need help with wget command.
Topic archived. No new replies allowed.