Come up with a program that prompts the user to enter three movies and display the entered information using your understanding of data strucures.

// Structures3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<string>
#include<sstream>

using namespace std;
# define N_movies 3

struct movies_t{

    string title;
    int year;
}
films[N_movies];// array of object films

void printmovie(movies_t movies);

int main(int argc, char* argv[])
{
    string mystr;int n;

    for(n=0;n<N_movies;n++)
    {
        cout<<"Enter Title";
        getline(cin,films[n].title);cin.ignore(100,'\n');
        cout<<"Enter year ";getline(cin,mystr);cin.ignore(100,'\n');
        stringstream(mystr)>>films[n].year;
    }
    cout<<"You have entered these movies";
    for(n=0;n<N_movies;n++)
    {
        printmovie(films[n]);
    }
    return 0;
    }
    void printmovie(movies_t movie){
        cout<<movie.title<<"\t";
        cout<<movie.year<<"\t"<<"\n";
    }

What's your question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.