help Structure ptogram

The instructions are : 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)
Include a constructor that allows all four of these member data values to be specified at the time a MovieData variableis created. The program should create two MovieData variables and pass each on in turn to a function that dispalys the information about the movie in a clearly formatted manner.

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

using namespace std;

struct MovieData
{
	string title;                                                 //Title of movie.
	string director;                                              //Director's name.
	int    yearReleased;                                          // Year the movie was released.
	int    runningTime;		                                      //Running time in miuntes.
};

int main()
{
	MovieData movie;                                            // Title is an instance of the structure MovieData

	cout << "Name of the movie: ";                               //Asking for user input.
	cin >> movie.title;
	cin.ignore();

	cout << "What is the name if of the director?: ";
	cin >> movie.director;

	cout << "Year the movie was released: ";
	cin >> movie.yearReleased;

	cout << "What is the running time for the movie in minutes: ";
	cin >> movie.runningTime;


	/**************************
	* Displaying the results. *  // Need to change this to a function.
	**************************/

	cout << "Title : " << movie.title;
	cout << "director: " << movie.director;
	cout << "Released: " << movie.yearReleased;
	cout << "Running Time: " << movie.runningTime;

	system("pause");
	return 0;
}
Hey there. I'd like to point out that you forgot one thing: You haven't created a constructor for your MovieData struct as asked by the question. Also, I think that you must create the variables using the constructor not by getting user input and setting it to the struct. Don't you know how to create a function? Your code should be something similar to this:

Functions tutorial: http://www.cplusplus.com/doc/tutorial/functions/

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

using namespace std;

struct MovieData
{
	string title;
	string director;
	unsigned int yearReleased;
	unsigned int runningTime;

	MovieData(string til, string dir, unsigned int yr, unsigned int rT); //Constructor
};

//Define the constructor below
MovieData::MovieData(string til, string dir, unsigned int yr, unsigned int rT)
{
	title = til;
	director = dir;
	yearReleased = yr;
	runningTime = rT;
}

//Define a function below to display the movie info
void displayMovieInfo(MovieData movieName)
{
	cout << "---------------" << endl;
	cout << "Title: " << movieName.title << endl;
	cout << "Director: " << movieName.director << endl;
	cout << "Year Released: " << movieName.yearReleased << endl;
	cout << "Running Time: " << movieName.runningTime << "mins" << endl;
	cout << "---------------\n" << endl;
}

int main() //The main function
{
	//Create two MovieData variables using the constructor
	MovieData movie1("Epic Movie", "StormboyXZ", 2014, 70);
	MovieData movie2("Someother Movie", "Stormboy", 2012, 120);

	//Display the movie info using our displayMovieInfo() function
	displayMovieInfo(movie1);
	displayMovieInfo(movie2);

	return 0;
}
Just so you know I wasn't done. And if you looked at what i had typed you see that I know there are things that need to be changed. I don't need critics just help, I am a student after all.
can you explain why you used an unsign int instead of an int?
So what's the problem? You haven't actually asked us anything.
i was asking why use an unsigned int instead of an int.
i was asking why use an unsigned int instead of an int.

I wrote my question at the same time as you, so I didn't see that. I was writing in response to your original post, in which you posted a load of code and a description, but didn't actually ask any question or tell us what your problem was.

I assume Stormboy used unsigned int because it's impossible to have a negative year, and impossible to have a negative running time.
can you explain why you used an unsign int instead of an int?


Unsigned int variables cannot have any negative value. In this case, a year can never be negative and time too cannot be negative. Therefore its better to use unsigned int instead of the regular int.
Topic archived. No new replies allowed.