Anybody knows why

This code runs like a bulldozer and does not actually obay the "if " rules?
"titles" is a string and "films.[]titel" / "films.[]type" is a vector.

Can anybody find why it bugs?

Thanks in advance!

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

cout << "Add a title << endl;
		getline(cin, titles);
		cout << "_________________________________________________"<< endl;
		cout << ":" << endl;
		cout << "filmen " << titles << " har lagts till " << endl;
		cout << "Please add the type of movie you want to add: <dvd or blueray>:\n_________________________________________________" << endl;
		getline(cin, typ);
		cout << "the type " << typ << " has been added " << endl;

for (int i = 0; i < films.size(); i++)
{
	if (films[i].titel != titles||films[i].type != titles) //Kontrollera att filmens namn inte redan finns i registret.
	{
		cout << endl;
	}
		if (typ != ("dvd") == 0 || typ != ("blueray") == 0) 
		{
			films.push_back(Film(titles,typ));
		}
		else if (typ == ("dvd") == 0 || typ == ("blueray") == 0)
		{
			films.push_back(Film(titles,"undefined"))
			cout << "Type ok is renamed to'undefined' " << endl;
		}
	else if (indx == -1)
	{
		cout << "test";
	}
	i=films.size();
} 
if (typ != "dvd" || typ != "blueray") should fix it. Same for the else if. You might want to read about if/else statements in the reference in the side bar over there. <---
Last edited on
For Mats.
http://www.cplusplus.com/doc/tutorial/control/

Read up on that to understand "if" statements and a few other control statement.
If the intention is to do something if typ is equal to either "dvd" or "blueray", and something else if it isn't so, there is no need to specify the condition twice (in both the if and else block). Just put it once, and the else will take care of the condition where it is false.

Also, if this is one condition:
if (typ == "dvd" || typ == "blueray")
then the inverse condition is this:
if (typ != "dvd" && typ != "blueray")
Notice the use of && in the second case. But like I said, you don't need both.
Topic archived. No new replies allowed.