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