C++ programing question: I don't understand why I am getting this error. can someone help me please. I have attached my code files and error.
Error
Code
Main.cpp
#include <stdio.h>
#include <iostream>
#include"MovieSelectorHeader.h"
#include"MovieSelectionFunctions.cpp"
int main()
{
int choice=1;
while(choice) ///loop until Seat menu return 0
{
choice= MovieSelectorMenu();
}
cout<<"\n\t----Good Bye!----\t" << endl; /// good bye message
}
Function file
#include "MovieSelectorHeader.h"
int MovieSelectorMenu()
{
char Choice;
cout << "Moive Selector Menu\n"
<< endl;
cout << "Display Movie List :D" << endl;
cout << "Search for Movie :S" << endl;
cout << "Quit :Q" << endl;
cout << "Enter your Choice :";
cin >> Choice; ///user input choice
if (Choice == 'd' || Choice == 'D')
{
fillDatabase();
display();
return 1;
}
else if (Choice == 's' || Choice == 'S')
{
linearSearch();
return 1;
}
else if (Choice == 'q' || Choice == 'Q')
{
return 0; /// return 0 and exit the program
}
else
{
cout << "\n Please enter a valid choice\t Try Again " << endl; ///return 1 and prompt the menu again
return 1;
}
}
void fillDatabase()
{
fstream input_file;
input_file.open("MovieData.txt"); ///open Arrival file
if (!input_file.is_open()) ///if file open fails
{
cout << "Cannot open file" << endl;
exit(EXIT_FAILURE);
}
else
{
int i = 0;
///read every line in the file until end of file reached
while (!input_file.eof() && i < NUM_OF_MOVIES)
{
string ip, temp;
getline(input_file, ip); //reading a line
istringstream ss(ip); //using istringstream
getline(ss, items[i].Title, ','); //tokenising
getline(ss, temp, ',');
istringstream temp1(temp);
temp1 >> items[i].ReleaseYear; /*processing the year of release as an integer*/
getline(ss, items[i].Director, ',');
getline(ss, items[i].Genre, ',');
getline(ss, items[i].Starring[0], ',');
getline(ss, items[i].Starring[1], ',');
i++;
}
tot = i;
input_file.close(); ///close the file
}
}
void linearSearch()
{
cout << "Please enter the year of the movie in YYYY format: ";
int year;
cin >> year;
int found = 0; //for checking if the movie is found or not
for (int i = 0; i < tot; i++)
{
if (items[i].ReleaseYear == year)
{
cout << "\n";
cout << "Movie found in the database... \n\n";
cout << "Movie Title: " << items[i].Title << endl;
cout << "Release Year: " << items[i].ReleaseYear << endl;
cout << "Director: " << items[i].Director << endl;
cout << "Genre: " << items[i].Genre << endl;
cout << "Starring 1: " << items[i].Starring[0] << endl;
cout << "Starring 2: " << items[i].Starring[1] << endl;
found = 1;
}
}
if (found == 0)
{
cout << "\nSorry No movie found";
}
cout << "\n";
}
void display() //function to display the movie details
{
for (int i = 0; i < tot; i++)
{
cout << "\n";
cout << "Movie Title: " << items[i].Title << endl;
cout << "Release Year: " << items[i].ReleaseYear << endl;
cout << "Director: " << items[i].Director << endl;
cout << "Genre: " << items[i].Genre << endl;
cout << "Starring 1: " << items[i].Starring[0] << endl;
cout << "Starring 2: " << items[i].Starring[1] << endl;
cout << "\n";
}
}
Header file
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
#define NUM_OF_MOVIES 100
struct Movie
{
string Title;
int ReleaseYear;
string Director;
string Genre;
string Starring[2];
};
Movie items[NUM_OF_MOVIES]; //creating an array of 100 movie items
int tot; //variable that will be used to store the total number of movies in the file
int MovieSelectorMenu();
void fillDatabase();
void linearSearch();
void display();