Movie Data

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#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;

}
Last edited on
You forgot to mention the datatype before m2 here:
void GetMovieInfo(MovieData &m1, &m2)
and here
void MovieDisplay(MovieData m1, m2)
I think you mistakenly thought that you could you use initializer lists as argument lists, or something like that.
You can use initializer lists like this:
MovieData m1, m2, m3;
to have m1, m2 and m3 usable as MovieData variables.
But with argument lists you are not able to do such a thing.

It seems that the rest of the errors are caused because you use m2 because the syntax to make m2 was wrong.
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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#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;

}
Looks like when you are inputting the name, etc, you are using cin.ignore() to ignore the first character.
for me there's no reason for using cin.ignore() after all i don't know how it use :) and when i compile it looks like there's a bug in your code but i'm a little bit confused. this line:

1
2
3
4
5
6
//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.getline(m2.title, SIZE);


seems like contain a bug. it will print both commands in single line. btw, i modified it wihout cin.ignore() and my compiler is dev c++
I'm not sure why your MovieDisplay() function takes two parameters here. Wouldn't it be better to take one parameter and pass both your variables to it in separate calls?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

void MovieDisplay(MovieData m)
{
	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:  " << m.title << endl;
	cout << "Director's Name:  " << m.director << endl;
	cout << "Release Year:  " << m.year << endl;
	cout << "Movie Runtime in minutes:  " << m.minutesRunning << endl;
}

int main()
{
	MovieData member1, member2;

	// .. get movie info

	MovieDisplay(member1); // output first
	MovieDisplay(member2); // output second

	return 0;
}


And the same applies to GetMovieInfo().

The benefit of computers is that they can do the repetitive stuff easily so you shouldn't need to repeat code the way you have. Just call it twice.
Topic archived. No new replies allowed.