+ 1
Where is the problem?
#include<iostream> #include<string> #include<sstream> using namespace std; #define N_MOVIES 3; struct movies_t { string title; int year; } films [N_MOVIES]; void printMovie (movies_t movie); int main(){ string mystr; int n; cout << "Hello world programme! "; for (n = 0; n < N_MOVIES; n++){ cout << "Enter movie title: "; getline (cin, mystr); cout << "Enter year of release: "; getline (cin, mystr); string (mystr) >> films [n].year; } cout <<"\nYou have printed these movies:\n"; for (n = 0; n < N_MOVIES; n++) printMovie (films [n]); return 0; }
5 odpowiedzi
+ 4
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define N_MOVIES 3 // remove semicolon
struct movies_t
{
string title;
int year;
} films [N_MOVIES];
void printMovie (movies_t movie)
{
cout << "Title: " << movie.title
<< "\nYear : " << movie.year
<< "\n";
} // missing implementation
int main()
{
cout << "Hello world programme!\n";
for (int n = 0; n < N_MOVIES; n++)
{
cout << "Enter movie title: ";
getline (cin, films[n].title);
cout << films[n].title << "\n";
cout << "Enter year of release: ";
cin >> films[n].year;
cout << films[n].year << "\n";
cin.ignore();
} // direct field input
cout << "\nYou have printed these movies:\n";
for (int n = 0; n < N_MOVIES; n++)
printMovie(films[n]);
return 0;
}
+ 3
Where have you defined your printMovie method? Do not use a semicolon in the #define.
+ 2
Thanks. I guess I was just 'TIRED'!
+ 2
Ipang, I gat it, though I had copied it from an external compiler...CPP N IDE
+ 1
GRANDEHilary
Please for next time, save the code and share the link rather than pasting raw text code. Especially when the code is big (more than 10 lines).
It is more convenient to review a saved code rather than having to copy raw text into editor for testing : )