im working on a program who the user enters data of a Movie: name, Director, and playtime im on my last error but i cant see the where the problem is ore what to do i trayed to change some parts in the code to see the problem with no luck.

#include "stdafx.h"
#include "cstdlib"
#include "iostream"
#include "iomanip"
#include "string"
#include "list"
#include "sstream"
#include "stdlib.h"

using namespace std;
struct dvd {
       string name;
       string director;
       string playtime;
       };
void movie(list<string> lista);
void director(list<string> lista);
void playtime(list<string> lista);
void write(list<string> lista);

int main(int argc, char *argv[])
{
    list<string> lista;
    list<string>::iterator it = lista.begin();
    for (int i=1; i<=2; it++){
    it++;
    }

    dvd movie;

    movie(lista);
    lista.insert (it,movie.name);

    director(lista);
    lista.insert (it,movie.director);

    playtime(lista);
    lista.insert (it,movie.playtime);

    write(lista);
    lista.clear();
    write(lista);
    return 0;
}
void movie(list<string> lista)
{
    dvd movie;
    string M;
    cout << "Movie: ";
    getline(cin, movie.name);
    lista.push_back(movie.name);
}
void director(list<string> lista)
{   
    dvd movie;
    cout << "Director: ";
    getline(cin, movie.director);
    lista.push_back(movie.director);
}

void playtime(list<string> lista)
{
    dvd movie;
    cout << "Playtime: ";
    cin >> movie.playtime;
    cin.ignore(1000, '\n');
}


void write(list<string> lista)
{
    cout << "\nResult: \n";
    list<string>::iterator it;
    for (it = lista.begin(); it != lista.end(); it++){
        cout << *it << endl;
    }

}
mvmalderen commented: Code tags on first post :) +8

Recommended Answers

All 3 Replies

There's a name conflict between the object 'movie' (which you created from your struct) and between your function movie:
I corrected the code by changing the name 'movie' to 'movies' for every instance of DVD:

/* I've also changed your include directives */

#include <iostream>
#include <string>
#include <list>


using namespace std;

struct dvd {
       string name;
       string director;
       string playtime;
       };
       
void movie(list<string> lista);
void director(list<string> lista);
void playtime(list<string> lista);
void write(list<string> lista);

int main(int argc, char *argv[])
{
    list<string> lista;
    list<string>::iterator it = lista.begin();
    for (int i=1; i<=2; it++){
    it++;
    }

    [B]dvd movies;[/B]

    movie(lista);
    lista.insert (it,[B]movies[/B].name);

    director(lista);
    lista.insert (it,[B]movies[/B].director);

    playtime(lista);
    lista.insert (it,[B]movies[/B].playtime);

    write(lista);
    lista.clear();
    write(lista);
    return 0;
}
void movie(list<string> lista)
{
    dvd [B]movies[/B];
    string M;
    cout << "Movie: ";
    getline(cin, [B]movies[/B].name);
    lista.push_back([B]movies[/B].name);
}
void director(list<string> lista)
{   
    dvd [B]movies[/B];
    cout << "Director: ";
    getline(cin, [B]movies[/B].director);
    lista.push_back([B]movies[/B].director);
}

void playtime(list<string> lista)
{
    dvd [B]movies[/B];
    cout << "Playtime: ";
    cin >> [B]movies[/B].playtime;
    cin.ignore(1000, '\n');
}


void write(list<string> lista)
{
    cout << "\nResult: \n";
    list<string>::iterator it;
    for (it = lista.begin(); it != lista.end(); it++){
        cout << *it << endl;
    }

}

Look at lines
dvd movie;
movie(lista);
in int main()

What do you want movie to be: a function or a dvd structure?. Use a different name for the object or a different name for the function.

Note that it is alright to declare a dvd called movie in main(). But now, the global movie ( which is a funtion) will be hidden by local movie( which is a dvd).
You can call the global movie by using the scope resolution operator ::

int main(int argc, char *argv[])
{
    list<string> lista;
    list<string>::iterator it = lista.begin();
    for (int i=1; i<=2; it++){
    it++;
    }

    dvd movie;


    ::movie(lista); //look here
    lista.insert (it,movie.name);

The correct code tags in C++ forums are:
[code=cplusplus] //your code

[/code]
This helps to highlight syntax.
Note that there will be more (logical)errors when you will fix this one.

[edit]
Tux>/* I've also changed your include directives */
I thank you for that. This was one more point that I wanted to tell him.
Why is the OP buddering the compiler to process extra header files when he can just use 3:

#include <iostream>
#include <string>
#include <list>

Rest are useless!!

Look at lines
dvd movie;
movie(lista);
in int main()

What do you want movie to be: a function or a dvd structure?. Use a different name for the object or a different name for the function.

Note that it is alright to declare a dvd called movie in main(). But now, the global movie ( which is a funtion) will be hidden by local movie( which is a dvd).
You can call the global movie by using the scope resolution operator ::

int main(int argc, char *argv[])
{
    list<string> lista;
    list<string>::iterator it = lista.begin();
    for (int i=1; i<=2; it++){
    it++;
    }

    dvd movie;


    [COLOR="Green"]::movie(lista);[/COLOR]
    lista.insert (it,movie.name);

The correct code tags in C++ forums are:
[code=cplusplus] //your code

[/code]
This helps to highlight syntax.
Note that there will be more (logical)errors when you will fix this one.

Thanks for the help :) i wanted the movie to be a function.

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.