I'm in a computer programming class and having trouble. The assignment is:

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)

The program should create two MovieData variables, store values in their members, and pass each one, in turn, to a function that displays the information about the movie in a clearly formatted manner.

I created my program, but getting errors. I guess I don't know exactly what they are asking for. Thanks for any help you can give.

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

const int SIZE = 50;

struct MovieData
{
	char title[SIZE];
	char director[SIZE];
	int year;
	int minutesRunning;
};

void GetMovieInfo(MovieData&);
void MovieDisplay(MovieData);

int main()
{
	MovieData member1, member2;

	GetMovieInfo(member1, member2);
	MovieDisplay(member1, member2);
	return 0;
}

void GetMovieInfo(MovieData &m1, &m2)
{
//Get movie title
	cout << "Enter the title of the movie:  ";
	cin.ignore();
	cin.getline(m1.title, SIZE);

	//Get director's name
	cout << "Enter the Director's name of the movie:  ";
	cin.ignore();
	cin.getline(m1.director, SIZE);

	//Get the release year
	cout << "Enter the year the movie was released:  ";
	cin >> m1.year;

	//Get the movie runtime in minutes
	cout << "Enter runtime of the movie in minutes:  ";
	cin >> m1.minutesRunning;

	//Get movie title
	cout << "Enter the title of the movie:  ";
	cin.ignore();
	cin.getline(m2.title, SIZE);

	//Get director's name
	cout << "Enter the Director's name of the movie:  ";
	cin.ignore();
	cin.getline(m2.director, SIZE);

	//Get the release year
	cout << "Enter the year the movie was released:  ";
	cin >> m2.year;

	//Get the movie runtime in minutes
	cout << "Enter runtime of the movie in minutes:  ";
	cin >> m2.minutesRunning;
}

void MovieDisplay(MovieData m1, m2)
{
	//Display the movie information
	cout << "Below is the data of the desired movie:\n";
	cout << "Movie Title:  " << m1.title << endl;
	cout << "Director's Name:  " << m1.director << endl;
	cout << "Release Year:  " << m1.year << endl;
	cout << "Movie Runtime in minutes:  " << m1.minutesRunning << endl;

	//Display the movie information
	cout << "Below is the data of the desired movie:\n";
	cout << "Movie Title:  " << m2.title << endl;
	cout << "Director's Name:  " << m2.director << endl;
	cout << "Release Year:  " << m2.year << endl;
	cout << "Movie Runtime in minutes:  " << m2.minutesRunning << endl;

}

Recommended Answers

All 4 Replies

Post the first couple errors so that we can help you decipher them.

I can tell you right now that line 27 and 66 are wrong. Must be like this: void MovieDisplay(MovieData m1, MovieData m2) But then even that does not satisfy the program requirements. You have to pass the structures ONE at a time to that function, not both at the same time. Therefore that function should only have one parameter, not two.

Line 27 (and 66) void GetMovieInfo(MovieData &m1, &m2) Every function parameter needs to have its type fully defined. void GetMovieInfo(MovieData &m1, MovieData &m2) it is not like declaring a list of variables MovieData m1, m2; Also I would have thought you teacher will want to see functions taking a single parameter being called twice. What will you do if the next part of the assignment is "expand this program to handle an array of 10 movies"?

The only problem I had was

void (GetMovieInfo (MovieData &m1, MoviewData &m2)
void (GetMovieInfo (MovieData m1, MovieData m2)

There is also another problem. It display's the movie title with missing the first letter. (ex. entered title is Rush Hour and it displays ush Hour)

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

const int SIZE = 50;

struct MovieData
{
	char title[SIZE];
	char director[SIZE];
	int year;
	int minutesRunning;
};

void GetMovieInfo(MovieData&, MovieData&);
void MovieDisplay(MovieData, MovieData);

int main()
{
	MovieData member1, member2;

	GetMovieInfo(member1, member2);
	MovieDisplay(member1, member2);
	return 0;
}

void GetMovieInfo(MovieData &m1, MovieData &m2)
{
	
	cout << "First Movie\n\n";

	//Get movie title
	cout << "Enter the title of the movie:  ";
	cin.ignore();
	cin.getline(m1.title, SIZE);

	//Get director's name
	cout << "Enter the Director's name of the movie:  ";
	cin.ignore();
	cin.getline(m1.director, SIZE);

	//Get the release year
	cout << "Enter the year the movie was released:  ";
	cin >> m1.year;

	//Get the movie runtime in minutes
	cout << "Enter runtime of the movie in minutes:  ";
	cin >> m1.minutesRunning;

	cout << "\n---------------------------------\n";
	cout << "Second Movie\n\n";

	//Get movie title
	cout << "Enter the title of the movie:  ";
	cin.ignore();
	cin.getline(m2.title, SIZE);

	//Get director's name
	cout << "Enter the Director's name of the movie:  ";
	cin.ignore();
	cin.getline(m2.director, SIZE);

	//Get the release year
	cout << "Enter the year the movie was released:  ";
	cin >> m2.year;

	//Get the movie runtime in minutes
	cout << "Enter runtime of the movie in minutes:  ";
	cin >> m2.minutesRunning;
}

void MovieDisplay(MovieData m1, MovieData m2)
{
	cout << "\n---------------------------------\n";
	cout << "First Movie";
	//Display the movie information
	cout << "\n\nBelow is the data of the first movie entered:\n";
	cout << "Movie Title:  " << m1.title << endl;
	cout << "Director's Name:  " << m1.director << endl;
	cout << "Release Year:  " << m1.year << endl;
	cout << "Movie Runtime in minutes:  " << m1.minutesRunning << endl;

	cout << "\n---------------------------------\n";
	cout << "Second Movie";
	//Display the movie information
	cout << "\n\nBelow is the data of the second movie entered:\n";
	cout << "Movie Title:  " << m2.title << endl;
	cout << "Director's Name:  " << m2.director << endl;
	cout << "Release Year:  " << m2.year << endl;
	cout << "Movie Runtime in minutes:  " << m2.minutesRunning << endl;

}

The reason the first letter is missing is because you are calling ignore before you call getline. You still are passing 2 objects to your functions when you should only be passing one object.

void MovieDisplay(MovieData m1)
// instead of
void MovieDisplay(MovieData m1, MovieData m2)
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.