dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Movie Data

  1. #1
    Join Date
    May 2010
    Posts
    14

    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.

    Code:
    #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 by usafsatwide; June 16th, 2010 at 01:54 AM.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Movie Data

    I created my program, but getting errors.
    Do we have to guess what they are ?

    Code:
    void GetMovieInfo(MovieData&);
    
    
    void GetMovieInfo(MovieData &m1, &m2)
    {
    ...
    }
    Your declaration is not the same as your implementation. Also, 'm2' has no type.

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Movie Data

    The first thing that catches my eye is that your forward declaration for GetMovieInfo doesn't match your implementation.

    Code:
    void GetMovieInfo(MovieData&);
    
    //...
    
    void GetMovieInfo(MovieData &m1, &m2)
    and of course, this should probably be:
    Code:
    void GetMovieInfo(MovieData &m1,MovieData &m2)

  4. #4
    Join Date
    May 2010
    Posts
    14

    Re: Movie Data

    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)

    Code:
    #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;
    
    }

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Movie Data

    Code:
    cin.ignore();
    You are ignoring the first letter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)