:)
Hello experts, Im taking a C++ class and i was asked to Write a program that uses a structure named MovieData to store the following information about a movie:

Title
Director
Year Released
Running Time (in minutes)

I've come down to making it compile, but, when it couts the output, the line for "year released" and for "run time" is i think, the reference for those cells. I tried to dereference using the & (i.e &p.year... &p.time) operator and no luck,
it gives me a runtime error, any suggestions?
here is my code:

#include <iostream>
#include <iomanip>
using namespace std;

const int TITLE = 50;
const int RELEASED = 2000;
const int RUN_TIME = 300;
const int NAME_SIZE = 50;

struct movieData
{
	char title[TITLE];
	char director[NAME_SIZE];
	int year[RELEASED];
	int time[RUN_TIME];
};
void getInfo(movieData&);
void showInfo(movieData);
int main()
{
	movieData movie;
	getInfo(movie);
	showInfo(movie);
	return 0;
}


//Definition of getInfo
void getInfo(movieData &p)
{
//Get movie title
	cout << "Enter movie Title:\n";
	cin >> p.title;
	//Get movie director
	cout << "Enter movie's Director:\n";
	cin.ignore();
	cin.getline(p.director, NAME_SIZE);
	//Get year released
	cout << "Enter year movie was released:\n";
	cin >> p.year[RELEASED];
	cout << "Enter the movie's Running Time:\n";
	cin >> p.time[RUN_TIME];
}
//Definition of function showInfo
void showInfo(movieData p)
{
	cout << fixed << showpoint << setprecision(2);
	cout << "Movie Title: " << p.title << endl;
	cout << "Director Name: " << p.director << endl;
	cout << "Year Released: " << p.year << endl;
	cout << "Running Time: " << p.time << endl;
}

Do you really want an array to represent the year and the running time? so leave those as ints. Also, any title over 1 word gets truncated. Why not use a getline for that as well?

Do you really want an array to represent the year and the running time? so leave those as ints. Also, any title over 1 word gets truncated. Why not use a getline for that as well?

jonsca thanks for your help, I tried different things and did not get far. code is working fine now.
thank you, here is the working code:

#include <iostream>
#include <iomanip>
using namespace std;

const int TITLE = 50;
const int RELEASED = 2000;
const int NAME_SIZE = 50;

struct movieData
{
	char title[TITLE];
	char director[NAME_SIZE];
	int year;
	int time;
};
void getInfo(movieData&);
void showInfo(movieData);
int main()
{
	movieData movie;
	getInfo(movie);
	showInfo(movie);
	return 0;
}


//Definition of getInfo
void getInfo(movieData &p)
{
//Get movie title
	cout << "Enter movie Title:\n";
	cin.getline(p.title, TITLE);
	//Get movie director
	cout << "Enter movie's Director:\n";
	cin.ignore();
	cin.getline(p.director, NAME_SIZE);
	//Get year released
	cout << "Enter year movie was released:\n";
	cin >> p.year;
	cout << "Enter the movie's Running Time:\n";
	cin >> p.time;
}
//Definition of function showInfo
void showInfo(movieData p)
{
	cout << fixed << showpoint << setprecision(2);
	cout << "Movie Title: " << p.title << endl;
	cout << "Director Name: " << p.director << endl;
	cout << "Year Released: " << p.year << endl;
	cout << "Running Time: " << p.time << endl;
}

how about:

struct movieData
{
	std::string title;
	std::string director;
	int year;
	int time;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.