Help with Movie database

Hi!

I'm having some trouble understanding why my moviedatabase wont do what I want it to do.

First of all, in my if-part, why am I only allowed to fill in the type of media (i.e. DVD or BluRay) and not the title of the movie? And how can I fix it?

Secondly, why isn't my search function in the first else if working?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <vector>
#include <sstream>
#include <string> 
#include <algorithm>

using namespace std;

class Film
{
public:
    string Titel;
    string Typ;

// FUNKTION: Skriver ut filmens titel och typ
    void skrivUtFilm()
    {
		cout << endl;
		cout << "Titel: " << Titel << endl; // Skriver ut filmens titel
		cout << "Typ: " << Typ << endl; // Skriver ut filmens typ
     }
};

int main()
{
    vector<Film> Databas;             // Skapa en vektor av typen Film

    Film nyFilm;                    // För att kunna skapa en film behöver vi kunna spara den

    while (true)
    {
		// Skriver ut menyn:
		cout << " === FILMDATABAS === " << endl;
		cout << "1: Registera en ny film"	<< endl;
		cout << "2: S\x94k efter en film"   << endl;
		cout << "3: Skriv ut filmlistan"	<< endl;
		cout << "0: Avsluta"	<< endl;
		cout << "Ange ditt val: ";

		char menySelection; // Användarens val
		cin >> menySelection;

	if (menySelection == '1') // <----- Need help here !!
        {
	    cout << "\n\n1: Registrera en ny film\n";
            cout << "Ange filmens Titel: ";
			getline(cin, nyFilm.Titel);
            cout << endl;

			cout << "Ange filmens Typ: ";
            getline(cin, nyFilm.Typ);
            cout << endl;

            // Vi lägger vårt filmobjekt i vektorn
			Databas.push_back( nyFilm );
		}
		else if (menySelection == '2') // <--- Need help here!
		{
			string objekt;
			getline(cin, objekt);

			vector<Film>::iterator it;

			it = find_if(Databas.begin(), Databas.end(),[&] ( const Film &f )
			{
				return ( f.Titel == objekt);
			});
		}
		else if (menySelection == '3') // Skrivet ut alla filmer i Filmarkivet
        {
			cout << "\n=========\n";
			cout << "Filmlistan\n";
			for(int i=0; i<Databas.size(); i++)
            {
			Databas[i].skrivUtFilm(); // Skriver ut dem med hjälp av skrivUtFilm();
            }
			cout << "\n=========\n";
            cout << "\n\nTryck p\x86 ENTER f\x94r att \x86terv\x84nda till menyn.\n\n";
            cin.get();
		}
		else if (menySelection == '0')
		{
			break;
        }
		else   
		{
			cout << "Ogiltigt val!\n." << endl;
		}
    }
	cin.get();
	return 0;
}


Thanks in advanced :)
Giriko
Hi Giriko, I'm only a beginner, but adding the following two lines of highlighted code starting at line 40 enabled me to add a film title.

char menySelection; // Användarens val
cout <<"Enter the number of your selection: ";
cin >> menySelection;
cin.get();

That's all I know at present. Cheers, Don

Thank you, Don!

Now I'm able to both enter the name and mediatype of the movie, I'm really a beginner and this exercise really caught me offgaurd. :)

Now its just a matter of how to be able to search for movies added to the database, because at the moment, I am able to write what I want to search for, but when I press enter, it just goes back to the menu.
Topic archived. No new replies allowed.