#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
struct movieInfo{
string id;
string title;
string actor1;
string actor2;
int released;
float rating;
};
void displayMenu();
void displayMovies(movieInfo *ptr, int);
int main(){
int choice;
constint MAX_MOVIE = 100;
movieInfo info[MAX_MOVIE];
movieInfo *ptr = new movieInfo[MAX_MOVIE];
ifstream inputFile;
inputFile.open("program2_library.txt");
if (!inputFile)
{
cout << "ERROR: File not found! " << endl;
}
int total = 0;
while (inputFile.good()){
getline(inputFile, ptr[total].id);
getline(inputFile, ptr[total].title);
getline(inputFile, ptr[total].actor1);
getline(inputFile, ptr[total].actor2);
inputFile >> ptr[total].released;
inputFile >> ptr[total].rating;
total++;
}
inputFile.close();
do{
int movies = 4;
displayMenu();
cout << "Enter your choice: ";
cin >> choice;
switch(choice){
case 1:
displayMovies(ptr, movies);
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
cout << "ERROR: choice not valid! " << endl;
}
}
while (choice != 5);
return 0;
}
void displayMenu(){
cout << "Menu " << endl;
cout << endl;
cout << "1. Display movies sorted by title " << endl;
cout << "2. Display movies sorted by rating " << endl;
cout << "3. Lookup title and actors by id " << endl;
cout << "Lookup id by title and either actor " << endl;
cout << "Quit the program " << endl;
}
void displayMovies(movieInfo *ptr, int movies){
for (int i = 0; i < movies; i++){
cout << ptr[i].id << " ";
cout << ptr[i].title << " ";
cout << ptr[i].actor1 << " ";
cout << ptr[i].actor2 << " ";
cout << ptr[i].released << " ";
cout << ptr[i].rating << " " << endl;
}
}
Below is my output:
1 2 3 4 5 6 7 8 9 10 11 12
Menu
1. Display movies sorted by title
2. Display movies sorted by rating
3. Lookup title and actors by id
4. Lookup id by title and either actor
5. Quit the program
Enter your choice: 1
A201 Avengers: Endgame Scarlett Johansson Chris Evans 2019 8.6
Despicable Me 3 Steve Carell Kristen Wiig 2017 6.1
Neighbors Zac Efron Rose Byrne 2014 6.3 0 0
0 0
My question is, why doesn't the movie ID's print for lines 2,3,4
and why does the fourth line output zeros rather than a movie description
from the text file? I've been stuck on it since yesterday and any input is greatly appreciated.