You can download the storage.txt
here#include <iostream>
#include <fstream>
using namespace std;
typedef struct {
string name;
int year;
} Comedy;
void readFromFile (Comedy films[], const int SIZE) {
ifstream file;
file.open("storage.txt", ifstream::in);
if (!file.is_open()) {
cout << "Unable to open the file" << endl;
}
for ( int i = 0; i < SIZE; i++ ) {
file >> films[i].year >> films[i].name;
}
}
int main() {
const int SIZE = 56;
Comedy films[SIZE];
int start, end;
readFromFile(films, SIZE);
cout << "Please input two years : the one you want to start with, and the one you want to finish with. Proper ones 1960-2014" << endl;
cin >> start >> end;
for ( int i = 0; i < SIZE; i++ ) {
if (films[i].year >= start && films[i].year <= end ) {
cout << films[i].name << endl;
}
}
return 0;
}
Comments
Leave a comment