in response to an inclass exercise where the following question was possed: write a program using structures, which will capture a list of 10 movies, the data members should be title and year.
the problem is the program is not capturing all the details and is printing unintelligible information. what might be wrong with my code am using Visual Basic C++ 6.0. IDE

#include "stdAfx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

struct movies_2015{string title; int year;}your_movies[10];

void create_title_year(movies_2015 movies[]);

void print_movie(movies_2015 mov[]);

int main()
{
create_title_year(your_movies);
print_movie(your_movies);
return 0;
}

void create_title_year(movies_2015 movies[])
{
        string mystr;
    for(int i=0;i<10;i++){
        cout<<"Enter Movie Title: ";
        getline(cin,movies[i].title);
        cin.ignore(100,'\n');
        cout<<endl;
        cout<<"Enter Year: ";
        getline(cin,mystr);
        stringstream(mystr)>>movies[i].year;
        cout<<endl;}
}

void print_movie(movies_2015 mov[])
        {
        cout<<"Movie Title\tYear"<<endl;
    for(int i=0;i<10;i++){
        cout<<mov[i].title<<" ( "<<mov[i].year<<" ) "<<endl;
        }
}

Recommended Answers

All 3 Replies

Your code seems to work fine for me when I compiled it with MinGW after I commented out #include "stdAfx.h".

Note that "Visual Basic C++ 6.0" is not a thing did you mean Visual C++ 6 which is rather old?

meant visual c++ 6.0 thanks for the correction. Do you suppose its the problem is with the compiler most of my code runs but when i get to use the getline function repeatedly i get output related problems. i think i should upgrade or migrate to some other compiler. Once again thank you !

I supose it may be the compiler and it certainly wont hurt to use a more up to date one but from my recollection I would have thought the Visual C++ 6 compiler should be capable of handling this code.

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.