Need help with check.

My intent was to convert the string variable for the year to an integer data type. The code compiles but now cannot run on my system. I'm not sure what's going as to what the program is displaying.

Objective:
rompt the user for two years. Print all Comedy movies that were released between those two years.


#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;


struct Movie
{
string name;
string year;
string genre;
};

void load_movie_database(Movie mlist[], int size)
{
ifstream data_store;
data_store.open("movie_database.txt");

if(!data_store)
{
cout << "Could not find file..." << endl;
exit(0);
}
int counter = 0;
while (!data_store.eof())
{
string name, year, genre;

getline(data_store, name);
getline(data_store, year);
getline(data_store, genre);

mlist[counter].name = name;
mlist[counter].year = year;
mlist[counter].genre = genre;
counter++;
}
data_store.close();
}

void year_check(Movie mlist[], int year1, int year2, int size)
{
for(int counter = 0; counter < size; counter ++)
{
int temp;
temp = atoi(mlist[counter].year.c_str());

if (temp >= year1 || temp <= year2)
{
cout << mlist[counter].name << endl;
}

}
}

int main()
{
int const size = 170000;
Movie mlist[size];
int year1, year2;
cout << "Comedy Movie Finder" << endl;
cout << "Enter beginning year" << endl;
cin >> year1;
cout << "Enter ending year" << endl;
cin >> year2;
load_movie_database(mlist, size);
year_check(mlist, year1, year2, size);


return 0;
}
Always post code in the code tag ("<>")

1) Your size is always 170000
2) You are not using size in void load_movie_database
3) In void year_check the loop is going to run for 170000 times even if "movie_database.txt" has less than those many entries
4) if (temp >= year1 || temp <= year2) is logically incorrect if you want to print the movies between these years. Currently it will print even if the year is not less than ending year. Use and instead of or
Thanks for the help.
I will next time I post something up.

helped a lot!
Topic archived. No new replies allowed.