I am suppose to be creating a program that uses a structure named Moviedata to store the following information about the 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 movie in a clearly formatted manner.

Then I am suppose to Modify the Movie Data progam written to include two additional members that hold the movie's production costs and first-year revenues. Modoify the funtion that displays the movie data to display the title directore release year running time and first year's profit or loss.

This is what I have so far and I don't think I am on the right track.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;int main ()

structure Moviedata;

int movie title;
int movie director;
int year released;

cout << “Enter the movie title “;
cin.getline(movie title);

cout << “Director: “’
cin.getline (Director);

cout <<”Year of release:”;
cin.getline(year of release: “;


cout << Here is the information on movie”;

If anyone can give me further assistance I would greatly appreciate it. I am not doing very well.

The body of the main() function should be enclosed in curly brackets just like any other function body.

In C++ user defined type is declared with keywords class or struct, not structure. The struct/class type needs to be declared before any variable of that struct/class type is declared or used. The declaration of the struct/class is generally done after the list of includes and before main() or in another file that is linked to the current program by listing the appropriate header file in the list of includes in the current program.

listing of included files  
struct/class declarations if not included
int main()
{
}

Variable names cannot include spaces.

getline() takes three parameters, which need to separated by commas.

The variable passed to getline() must be a C style string, not an int.

have you tried to compile that program? what are the compiler errors?

tructure Moviedata;

int movie title;
int movie director;
int year released;

That is not the correct way to declare a structure. Here is how it should be done. Since you are writing a c++ program you should use std::string instead of char arrays.

structure Moviedata
{
   string movieTitle;
   string movieDirector;
   int yearReleased;
};

Here is some of the program to get you started on the right track.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;


structure Moviedata
{
   string movieTitle;
   string movieDirector;
   int yearReleased;
};

int main()
{
   // declare an object of type struct MovieData
   structure Moviedata data;
   // display a prompt
   cout << “Enter the movie title “;
   // get movie title from keyboard
   getline(cin,data.movieTitle);


   return 0;
}

cppreference doesn't list structure as a key word in either C or C++. Is it really a keyword?

I am getting all kinds of errors. I am new to c++ and am trying to get the hang of it.

Welcome to the learning curve. We've all been there. I still go there with every program I write, (which explains why I'm a hobbyist and not a professional).

We've pointed out a fair number of the errors. Try to fix them, recompile and see what errors are left. If you aren't sure what to do then post the relevant code and error messages with reference line if available.

This is what I have now and the error I'm getting is

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

structure Moviedata
{
string movieTitle;
string movieDirector;
int yearReleased;
}; int runningtime;
int main()
{
// declare an object of type struct MovieData
structure Moviedata data;
// display a prompt
cout << “Enter the movie title “;
// get movie title from keyboard
getline(cin,data.movieTitle);
getline(cin,data.stringdirector);
getline(cin,data.int yearreleased);
getline(cin,data.movierunningtime);

return 0;
}


Error

3 e:\c__ass~1\untitl~3.cpp sstream: No such file or directory

>>#include <sstream>
that should be <strstream>

but since you are not using it in your program you can savely just delete that line.

I think the code getline(cin,data.stringdirector); should be written as
getline(cin,data.movieDirector) ;
and secondly int runningtime; should be declared inside Structure defination if you want to define as a Structure member

struct Moviedata
{
string movieTitle;
string movieDirector;
int yearReleased;
int runningtime;


};

int main ()
{
Struct Moviedata movie;
----
-----
-----

Cin>> movie.movieTitle


}

It seems I just change one thing and then I get more errors.

#include <iostream>
#include <string>
using namespace std;
 structure Moviedata
 {
   string movieTitle;
   string movieDirector;
   int yearReleased;
};
int main()
{
   // declare an object of type struct MovieData

    structure Moviedata ;
   // display a prompt
   cout << “Enter the movie title “;
   // get movie title from keyboard
   cin.getline(movie.title,string movietitle);
       cout << "MovieDirector" director.name << endl;
   getline(cin,data.stringdirector);
    cout << " Year movie released: ";
   getline(cin,data.int yearreleased);
   getline(cin,data.runningtime);

   cout << movietitle << endl;
    
 

   return 0;
}

Errors

7 e:\c__ass~1\untitl~3.cpp syntax error before `{'
11 e:\c__ass~1\untitl~3.cpp parse error before `}'
18 e:\c__ass~1\untitl~3.cpp `structure' undeclared (first use this function)
18 e:\c__ass~1\untitl~3.cpp (Each undeclared identifier is reported only once
18 e:\c__ass~1\untitl~3.cpp for each function it appears in.)
18 e:\c__ass~1\untitl~3.cpp parse error before `;'
20 e:\c__ass~1\untitl~3.cpp parse error before character 0223
22 e:\c__ass~1\untitl~3.cpp `movie' undeclared (first use this function)
22 e:\c__ass~1\untitl~3.cpp parse error before `)'
23 e:\c__ass~1\untitl~3.cpp parse error before `.'
24 e:\c__ass~1\untitl~3.cpp `data' undeclared (first use this function)
26 e:\c__ass~1\untitl~3.cpp parse error before `)'
31 e:\c__ass~1\untitl~3.cpp `movietitle' undeclared (first use this function)

You need to pay more attention to detail, the variable names in the structure, and capitalization.
>>cin.getline(movie.title,string movietitle);
that is the incorrect use of getline. There are two versions of getline, one for C-style character arrays and the other for std::string objects. You used the wrong version

getline( cin, movie.movieTitle);

>>cout << "MovieDirector" director.name << endl;
that line is incorrect. Again, pay attention to detail, spelling and capitalization.

cout << "MovieDirector"<< movie.movieDirector << endl;

I guess the one thing that is confusing me now is this error

7 e:\c__ass~1\untitl~3.cpp syntax error before `{'


I don't see anything wrong with this.

I am really sorry to be bugging but I guess I am really confused at this point. This assignment is due tonight and I guess I am not getting it.

structure Moviedata  //to my knowledge structure is not a keyword, change it to struct not structure and see what happens

int main()
{

    structure Moviedata ;  //this doesn't declare an object of type Moviedata but this would----Moviedata data;  Note in C++ you don't use the keyword struct or class when decalaring an object of the type, you use struct/class only when declaring the struct/class itself.  

    cin.getline(movie.title,string movietitle);  //1) don't pass type names as arguments to functions.  2) this type of getline() takes a C style string as the first argument.  Since you are using STL strings as member variables of the Moviedata struct you want the other type of getline anyway (see the type you use below).  If you declare a variable of type Moviedata by the name of data then you could do something like this:
getline(cin, data.movieTitle);

    getline(cin, data.stringdirector); //1)there is no object by the name of data declared that I can see, and 2) even if there was, there is no member variable called stringdirector in the struct Moviedata

    getline(cin, data.int yearreleased); //again, 1) where is data declared as an object in your code.  2) don't pass the variable type name, just the variable name itself

    getline(cin, data.runningtime); //correct getline syntax for STL string, but runningtime isn't a member variable of struct Moviedata, if data is an object of type Moviedata

    cout << movietitle << endl; //movietitle isn't declared as a variable, but data.movieTitle would work, if that's what you want to do.

Maybe this will be easier to read:

structure Moviedata  // to my knowledge structure is not a keyword, 
                     // change it to struct not structure and see 
                     // what happens

int main()
{

    structure Moviedata ;  // this doesn't declare an object of type 
                     // Moviedata but this would----Moviedata data;  Note 
                     // in C++ you don't use the keyword struct or class 
                     // when decalaring an object of the type, you use 
                     // struct/class only when declaring the struct/class 
                     // itself.  

    cin.getline(movie.title,string movietitle);  // 1) don't pass type 
                     //     names as arguments to functions.  
                     // 2) this type of getline() takes a C style string  
                     //     as the first argument.  Since you are using STL 
                     //     strings as member variables of the Moviedata 
                     //     struct you want the other type of getline 
                     //     anyway (see the type you use below).  If you 
                     //     declare a variable of type Moviedata by the 
                     //     name of data then you could do something 
                     //     like this:
                     //             getline(cin, data.movieTitle);

    getline(cin, data.stringdirector); // 1)there is no object by the name 
                     //     of data declared that I can see, and 
                     // 2) even if there was, there is no member variable 
                     //     called stringdirector in the struct Moviedata

    getline(cin, data.int yearreleased); //again, 1) where is data declared 
                     //     as an object in your code.  
                     // 2) don't pass the variable type name, just the 
                     //     variable name itself

    getline(cin, data.runningtime); // correct getline syntax for STL 
                     //     string, but runningtime isn't a member variable 
                     //     of struct Moviedata, if data is an object of 
                     //     type Moviedata

    cout << movietitle << endl; // movietitle isn't declared as a variable, 
                     //     but data.movieTitle would work, if that's what 
                     //     you want to do.
Comments
Hard work. :) --joeprogrammer

Now that my assignments has been handed in can someone show me how this is done. I have tried and have changed what I was working on.

include <iostream>
#include <stdlib.h>
using namespace std;
 
 
struct Moviedata
{
         string movieTitle;
         string movie Director;
         int yearReleased;
         int runningtime;
 
};
int main()
{
  //Get data about a movie.
  cout <<"Enter the following data about a "
       <<"movie:\n";
  cout << "Title: ";
  cin.getline(movie.title);
  cout << "Director: ";
  cin >> Director.name;
  cout << "Year Released: ";
  cin.getline(int yearreleased, Year_size);
  cout << "Running time: ";
  cin.getline(movie.runningtime, Time_size);

  system("PAUSE");
      return 0;
}

I am suppose to be creating a program that uses a structure named Moviedata to store the following information about the 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 movie in a clearly formatted manner.

Then I am suppose to Modify the Movie Data progam written to include two additional members that hold the movie's production costs and first-year revenues. Modoify the funtion that displays the movie data to display the title directore release year running time and first year's profit or loss.

This is what I have so far and I don't think I am on the right track.

I won't get a response because my class is online and it was our last project. Please show me.

#include <iostream>
#include <string>
using namespace std;
 struct Moviedata{
   string movieTitle;
   string movieDirector;
   int yearReleased;
   int runningTime;
};
int main()
{
   // declare an object of type struct MovieData
 
    struct Moviedata movie;
   // display a prompt
    cout << "Enter the movie title :";
   // get movie title from keyboard
   cin >>movie.movieTitle;
....
....
....
   return 0;
}

I thought S.O.S. mentioned the use of code tags. There's a link at the top of the forum. There are letters and words on the back of the input box you typed your message in called a watermark that explains them -- no it's not just a dirty background. And you should have gotten a couple PM's about it....

When someone is new the codes you are taking about don't really mean anything. Maybe if things were explained a little better in your web your web site might be a little more user friendly. So I'm telling you, you know what you can do with your code. Well you can keep your like you can keep your web site because I wont be returning. ta ta. Your guys are rude!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Comments
Get a life kiddo and learn some manners

>When someone is new the codes you are taking about don't really mean anything.
Which is why you're supposed to read the forum rules and any announcements posted in the forum you're about the ask a question at.

>Maybe if things were explained a little better in your web your web site might be a little more user friendly.
They are explained pretty well, especially compared to other website forums. I mean, having an explanation in the watermark of the reply box? If you can't understand this, ask for help. Simply ignoring us just makes everyone mad, as there is a reason for code tags: it makes it much, much easier to read the code and thus help YOU. Neglection of code tags when needed only hurts yourself. Many old-timers will not even bother to reply to a post that lacks code tags.

>Your guys are rude!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
No, you are rude by not reading and obeying forum rules. If you want the best responses from someone in a coding forum... (I won't say it again)

This article has been dead for over six months. Start a new discussion instead.