77 895
Assignments Done
98,6%
Successfully Done
In August 2019

Answer to Question #42120 in C++ for aljoshua ramirez

Question #42120
Prompt the user for two years. Print all Comedy movies that were released between those two years.
Expert's answer
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions