Nov 24, 2014 at 5:41pm UTC
i have trouble printing out the movies starting with inputing only two letters.
#include <iostream> //cout, cin, endl,getline
#include <fstream> //ifstream
#include <cstdlib> // exit
using namespace std;
const int NUM_MOVIES = 116792;
struct Movie
{
string name;
string year;
string genre;
}; //dont forget semi colon
//this function takes a blank array and fills that array up with movie data
void load_movies(Movie blank_array[])
{
//step 1 : stream variable
ifstream data_store;
//step 2 : open file
data_store.open("movie_database.txt");
//step 3: processing the file
if(!data_store)
{
cout << "movie_database.txt is not in this directory" << endl;
exit(0); // end the program no matter where you are
}
for (int counter = 0; counter < NUM_MOVIES; counter++)
{
string name, year, genre;
getline(data_store, name);
getline(data_store, year);
getline(data_store, genre);
blank_array[counter].name = name;
blank_array[counter].year = year;
blank_array[counter].genre = genre;
}
//step 4: close file
data_store.close();
}
int main()
{
Movie movie_array[NUM_MOVIES];
load_movies(movie_array);
string first, second;
cout << "Begins-With Movie Finder" << endl;
cout << "Enter first character" << endl;
cin >> first;
cout << "Enter second character" << endl;
cin >> second;
//search for movies that correspond
//this loop visit all 116792 movies
for(int counter = 0; counter < NUM_MOVIES; counter++)
{
if (first == movie_array[counter].name
&& second == movie_array[counter]. name)
{
//display the movie
cout << movie_array[counter].name << endl;
}
}
return 0;
}
Nov 24, 2014 at 8:22pm UTC
Could you be more specific as to what you need help with?
Also, please make sure your code is enclosed [co de]between code tags[/code] so that it gets syntax highlighting and, more importantly, line numbers.
By the way, it is rude to PM users asking for help.
Last edited on Nov 24, 2014 at 8:23pm UTC