Movie Data

What am I doing wrong? I know it has to deal some where in the class and the void MovieData function. Is it 'cause I haven't declared the type of data it'll receive? I'm trying to make it into a reference and I don't want to pass each data individually, but as a whole into movie1; when it repeats, then passed into movie2. I don't wish to restate the questions and use the dot operator over and over again for movie1 and movie2. Can you help me? Thanks in advance.

FYI: I know I didn't add cost or revenue into the functions, working on the first challenge.

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
#include <iostream>
#include <string>

using namespace std;

class MovieData
{
private:

char title, director;

int year, time;

double costs, revenues;

public:

void movieData(MovieData&);
void displayData(MovieData);
}
void MovieData(MovieData &movie1, &movie2)
{
char title[256], director[256];

for (int repeat = 0; repeat < 2; repeat++)
    {
            cout << "Enter the title of the movie: "
            cin.getline(movie.title, 256);

            cout << "\nEnter the director of the movie: "
            cin.getline(movie.director, 256);

            cout << "\nEnter the year the movie was released (4-Digits): "
            cin >> movie.year;

            while ((movie1.year < 1000) || (movie1.year > 9999))
                  {
                         cout << "\n\nInvalid Input.\n\n\nThe year cannot be lower or higher than 4 digits: "
                         cin >> movie.year;
                  }

            cout << "\nEnter the running time of the movie in minutes: "
            cin >> movie.time;

            while (movie.time < 60)
                  {
                         cout << "Invalid Input.\n\n\nA movie consists greater than 60 minutes: "
                         cin >> movie.time;
                  }

                  cout << "\n\n";
     }
}
void DisplayData(MovieData &movie1, &movie2)
{
	cout << "Movie Title:  " << m1.title << "\n";
	cout << "Director's Name:  " << m1.director << "\n";
	cout << "Year Released:  " << m1.year << "\n";
	cout << "Movie Run-time:  " << m1.time << "\n";
	
	cout << "Movie Title:  " << m2.title << "\n";
	cout << "Director's Name:  " << m2.director << "\n";
	cout << "Year Released:  " << m2.year << "\n";
	cout << "Movie Run-time:  " << m2.time << "\n";  
}
int main ()
{
    
MovieData movie;

void MovieData(movie1, movie2);
void DisplayData(movie1, movie2);

system ("pause"); 
return 0;
}
Last edited on
had a quick lok.
the main issues:
1. You need a semi-colon at the end of your class dec (line 20).
2. You have declared your movieData() method in your class with a lower case 'm', which is fine, but when you come to declare it you're using an upper case 'M' (which would be the class's constructor). Also the number of parameters do not match the declaration (well, this:
void MovieData(MovieData &movie1, &movie2)
is illegal syntax). You also need scope resolution as you're writing the implementation outside of the class.
Last edited on
Hi Xesna, could you give us the error you get ? It would really help us to see what's wrong.
There's an error on line 25 stating the return type is invalid and for 28, unqualified id.

EDIT: I can't give all the errors since it immediately stops during its first encounter of an error.

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
#include <iostream>
#include <string>

using namespace std;

class MovieData
{
private:

char title, director;

int year, time;

double costs, revenues;

public:

void MovieData(MovieData &movie1, &movie2);
void displayData(MovieData &movie1, &movie2);
};
MovieData::void MovieData(MovieData &movie1, &movie2)
{
char title[256], director[256];

for (int repeat = 0; repeat < 2; repeat++)
    {
            cout << "Enter the title of the movie: "
            cin.getline(movie.title, 256);

            cout << "\nEnter the director of the movie: "
            cin.getline(movie.director, 256);

            cout << "\nEnter the year the movie was released (4-Digits): "
            cin >> movie.year;

            while ((movie1.year < 1000) || (movie1.year > 9999))
                  {
                         cout << "\n\nInvalid Input.\n\n\nThe year cannot be lower or higher than 4 digits: "
                         cin >> movie.year;
                  }

            cout << "\nEnter the running time of the movie in minutes: "
            cin >> movie.time;

            while (movie.time < 60)
                  {
                         cout << "Invalid Input.\n\n\nA movie consists greater than 60 minutes: "
                         cin >> movie.time;
                  }

                  cout << "\n\n";
     }
}
MovieData::void DisplayData(MovieData &movie1, &movie2)
{
	cout << "Movie Title:  " << movie.title << "\n";
	cout << "Director's Name:  " << movie.director << "\n";
	cout << "Year Released:  " << movie.year << "\n";
	cout << "Movie Runtime:  " << movie.time << "\n";
	
	cout << "Movie Title:  " << movie2.title << "\n";
	cout << "Director's Name:  " << movie2.director << "\n";
	cout << "Year Released:  " << movie2.year << "\n";
	cout << "Movie Runtime:  " << movie2.time << "\n";  
}
int main ()
{
    
MovieData movie;

void MovieData(movie1, movie2);
void DisplayData(movie1, movie2);

system ("pause"); 
return 0;
}
Last edited on
have you even read my post?

and this:
1
2
3
4
5
6
7
8
9
10
11
int main ()
{
    
MovieData movie;

void MovieData(movie1, movie2);  // -- You don't call methods like this.
void DisplayData(movie1, movie2); // --- You don't call methods like this.

system ("pause"); 
return 0;
}


Read:
http://www.cplusplus.com/doc/tutorial/functions/
and
http://www.cplusplus.com/doc/tutorial/classes/


Last edited on
I noticed it when I was looking it over today. Anyway, here is the code, but the issue now, is this:

cout << "\nEnter the title of the movie: ";
cin.getline(movie2.title2, MAX);


The question gets skipped and I'm not sure why and I don't want to use cin.ignore() since it has the tendency to drop the first character of a name. Also, I know it's pretty lengthy, but what can you expect? I barely covered the chapter since yesterday and trust me - I would love to shorten everything to one parameter if I knew how, as well as just calling the function twice, to shorten it.

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <iomanip>

using namespace std;

const int MAX = 60;

class MovieData
{
public:

int year, time, year2, time2;

double cost, revenue, cost2, revenue2;
  
char title[MAX], director[MAX], title2[MAX], director2[MAX];
};

void GetData(MovieData&, MovieData&);
void ShowData(MovieData, MovieData);

int main ()
{
MovieData movie1, movie2;

GetData(movie1, movie2);
ShowData(movie1, movie2);

system ("pause"); 
return 0;
}
void GetData(MovieData &movie1, MovieData &movie2)
{
            cout << "Enter the title of the movie: ";
            cin.getline(movie1.title, MAX);

            cout << "\nEnter the director of the movie: ";
            cin.getline(movie1.director, MAX);

            cout << "\nEnter the year the movie was released (4-Digits): ";
            cin >> movie1.year;

            while ((movie1.year < 1000) || (movie1.year > 9999))
                  {
                         cout << "\n\nInvalid Input.\n\n\nThe year cannot be lower or higher than 4 digits: ";
                         cin >> movie1.year;
                  }

            cout << "\nEnter the running time of the movie in minutes: ";
            cin >> movie1.time;

            while (movie1.time < 60)
                  {
                         cout << "Invalid Input.\n\n\nA movie consists greater than 60 minutes: ";
                         cin >> movie1.time;
                  }
                  
            cout << "\nEnter the cost of the movie: ";
            cin >> movie1.cost;            

            while (movie1.cost < 0)
                  {
                         cout << "Invalid Input.\n\n\nA movie cannot be lower than 0: $";
                         cin >> movie1.cost;
                  }
                  
            cout << "\nEnter the overall revenue the movie earned: $";
            cin >> movie1.revenue;
            
            while (movie1.revenue < 0)
                  {
                         cout << "Invalid Input.\n\n\nThe revenue cannot be lower than 0: $";
                         cin >> movie1.revenue;
                  }
     
            cout << "\nEnter the title of the movie: ";
            cin.getline(movie2.title2, MAX);

            cout << "\nEnter the director of the movie: ";
            cin.getline(movie2.director2, MAX);

            cout << "\nEnter the year the movie was released (4-Digits): ";
            cin >> movie2.year2;

            while ((movie2.year2 < 1000) || (movie2.year2 > 9999))
                  {
                         cout << "\n\nInvalid Input.\n\n\nThe year cannot be lower or higher than 4 digits: ";
                         cin >> movie2.year2;
                  }

            cout << "\nEnter the running time of the movie in minutes: ";
            cin >> movie2.time2;

            while (movie2.time2 < 60)
                  {
                         cout << "Invalid Input.\n\n\nA movie consists greater than 60 minutes: ";
                         cin >> movie2.time2;
                  }
                  
            cout << "\nEnter the cost of the movie: ";
            cin >> movie2.cost2;            

            while (movie2.cost2 < 0)
                  {
                         cout << "Invalid Input.\n\n\nA movie cannot be lower than 0: $";
                         cin >> movie2.cost2;
                  }
                  
            cout << "\nEnter the overall revenue the movie earned: $";
            cin >> movie2.revenue2;
            
            while (movie2.revenue2 < 0)
                  {
                         cout << "Invalid Input.\n\n\nThe revenue cannot be lower than 0: $";
                         cin >> movie2.revenue2;
                  }
            
                  cout << "\n\n";
}
void ShowData(MovieData movie1, MovieData movie2)
{
	cout << "Movie Title: " << movie1.title << "\n";
	cout << "Director's Name: " << movie1.director << "\n";
	cout << "Year Released: " << movie1.year << "\n";
	cout << "Movie Runtime: " << movie1.time << "\n";
	cout << "Movie Cost $" << movie1.cost << "\n";
	cout << "Movie Revenue $" << movie1.revenue << "\n"; 
	
	cout << "Movie Title: " << movie2.title2 << "\n";
	cout << "Director's Name: " << movie2.director2 << "\n";
	cout << "Year Released: " << movie2.year2 << "\n";
	cout << "Movie Runtime: " << movie2.time2 << "\n";
	cout << "Movie Cost $" << movie2.cost2 << "\n";
	cout << "Movie Revenue $" << movie2.revenue2 << "\n"; 
}
EDIT: The tutorials are just as vague as the book itself since it isn't targeting such a specific situation; rather than instigating, I suggest an explanation on areas specifically such like so below (i.e program) would be beneficial (something unrelated to calculations).

I appreciate it, nonetheless. In addition to, I cheated using the cin.ignore() by adding an extra spacing, which gets deleted when printing the results. I have finished it without any errors, but my question is, how would or, how can I shorten the line of code specifically using one parameter and calling the function twice?

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <iomanip>

using namespace std;

const int MAX = 60;

class MovieData
{
public:

int year, time, year2, time2;

double cost, revenue, cost2, revenue2;
  
char title[MAX], director[MAX], title2[MAX], director2[MAX];
};

void GetData(MovieData&, MovieData&);
void ShowData(MovieData, MovieData);

int main ()
{
MovieData movie1, movie2;

GetData(movie1, movie2);
ShowData(movie1, movie2);

cout << "\n\n\n";

system ("pause"); 
return 0;
}
void GetData(MovieData &movie1, MovieData &movie2)
{
     cout << "Enter the following information for the first movie.";
     
            cout << "\n\n\nEnter the title of the movie:  ";
            cin.getline(movie1.title, MAX);

            cout << "\nEnter the director of the movie: ";
            cin.getline(movie1.director, MAX);

            cout << "\nEnter the year the movie was released (4-Digits): ";
            cin >> movie1.year;

            while ((movie1.year < 1000) || (movie1.year > 9999))
                  {
                         cout << "\n\nInvalid Input.\n\n\nThe year cannot be lower or higher than 4 digits: ";
                         cin >> movie1.year;
                  }

            cout << "\nEnter the running time of the movie in minutes: ";
            cin >> movie1.time;

            while (movie1.time < 60)
                  {
                         cout << "Invalid Input.\n\n\nA movie consists greater than 60 minutes: ";
                         cin >> movie1.time;
                  }
                  
            cout << "\nEnter the cost of the movie: ";
            cin >> movie1.cost;            

            while (movie1.cost < 0)
                  {
                         cout << "Invalid Input.\n\n\nA movie cannot be lower than 0: $";
                         cin >> movie1.cost;
                  }
                  
            cout << "\nEnter the overall revenue the movie earned: $";
            cin >> movie1.revenue;
            
            while (movie1.revenue < 0)
                  {
                         cout << "Invalid Input.\n\n\nThe revenue cannot be lower than 0: $";
                         cin >> movie1.revenue;
                  }

     cout << "\n\nEnter the following information for the second movie.";
         
            cout << "\n\n\nEnter the title of the movie:" << "  ";
            cin.ignore();
            cin.getline(movie2.title2, MAX);

            cout << "\nEnter the director of the movie: ";
            cin.getline(movie2.director2, MAX);

            cout << "\nEnter the year the movie was released (4-Digits): ";
            cin >> movie2.year2;

            while ((movie2.year2 < 1000) || (movie2.year2 > 9999))
                  {
                         cout << "\n\nInvalid Input.\n\n\nThe year cannot be lower or higher than 4 digits: ";
                         cin >> movie2.year2;
                  }

            cout << "\nEnter the running time of the movie in minutes: ";
            cin >> movie2.time2;

            while (movie2.time2 < 60)
                  {
                         cout << "Invalid Input.\n\n\nA movie consists greater than 60 minutes: ";
                         cin >> movie2.time2;
                  }
                  
            cout << "\nEnter the cost of the movie: ";
            cin >> movie2.cost2;            

            while (movie2.cost2 < 0)
                  {
                         cout << "Invalid Input.\n\n\nA movie cannot be lower than 0: $";
                         cin >> movie2.cost2;
                  }
                  
            cout << "\nEnter the overall revenue the movie earned: $";
            cin >> movie2.revenue2;
            
            while (movie2.revenue2 < 0)
                  {
                         cout << "Invalid Input.\n\n\nThe revenue cannot be lower than 0: $";
                         cin >> movie2.revenue2;
                  }
            
                  cout << "\n\n";
}
void ShowData(MovieData movie1, MovieData movie2)
{
    cout << "\n\nFirst Movie:";
    
	cout << "\n\nMovie Title: " << setw(13) << movie1.title << "\n";
	cout << "Director's Name: " << setw(8) << movie1.director << "\n";
	cout << "Year Released: " << setw(11) << movie1.year << "\n";
	cout << "Movie Runtime: " << setw(9) << movie1.time << "\n";
	cout << "Movie Cost " << setw(11) << "$" << movie1.cost << "\n";
	cout << "Movie Revenue " << setw(8) << "$" << movie1.revenue << "\n"; 
	
	cout << "\n\nSecond Movie:";
	
	cout << "\n\nMovie Title: " << setw(13) << movie2.title2 << "\n";
	cout << "Director's Name: " << setw(8) << movie2.director2 << "\n";
	cout << "Year Released: " << setw(11) << movie2.year2 << "\n";
	cout << "Movie Runtime: " << setw(9) << movie2.time2 << "\n";
	cout << "Movie Cost " << setw(11) << "$" << movie2.cost2 << "\n";
	cout << "Movie Revenue " << setw(8) << "$" << movie2.revenue2 << "\n"; 
}
Last edited on
Topic archived. No new replies allowed.