in response to an inclass exercise where the following question was possed: write a program using structures, which will capture a list of 10 movies, the data members should be title and year.
the problem is the program is not capturing all the details and is printing unintelligible information. what might be wrong with my code am using Visual Basic C++ 6.0. IDE
#include "stdAfx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
struct movies_2015{string title; int year;}your_movies[10];
void create_title_year(movies_2015 movies[]);
void print_movie(movies_2015 mov[]);
int main()
{
create_title_year(your_movies);
print_movie(your_movies);
return 0;
}
void create_title_year(movies_2015 movies[])
{
string mystr;
for(int i=0;i<10;i++){
cout<<"Enter Movie Title: ";
getline(cin,movies[i].title);
cin.ignore(100,'\n');
cout<<endl;
cout<<"Enter Year: ";
getline(cin,mystr);
stringstream(mystr)>>movies[i].year;
cout<<endl;}
}
void print_movie(movies_2015 mov[])
{
cout<<"Movie Title\tYear"<<endl;
for(int i=0;i<10;i++){
cout<<mov[i].title<<" ( "<<mov[i].year<<" ) "<<endl;
}
}