Star wars and Lord of the rings if else statement troubles

Hi. I'm writing a code for class and it isn't working the way I would like it to. The program keeps spitting it out sentences that shouldn't be there at that time even if the user input doesn't agree with them. Any help would be much appreciated!

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

#include <iostream>
using namespace std;

int main () 
{
	string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
	cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
	cin >> movie;
	
	

	if (movie == "Starwars") {
		cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
		cin >> side;
	}
	
	else if (movie == "Lordoftherings") {
		cout << "Who is your favourite character? Enter Sam or Frodo: \n";
		cin >> character;
		}
		
	else (movie != "Starwars" || movie != "Lordoftherings"); {
	cout << "You don't don't like either of them? Are you crazy? \n";
		}		

		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else (side != "imperials" || side != "rebellion"); {
			cout << "You're a freelance? Good luck out there. \n";
			}
	
	
	
	
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else if (character != "Sam" || character != "Frodo"); {
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			}
	
	
return 0;	
 	 
	
}

Last edited on
1.
1
2
cout << "You don't don't like either of them? Are you crazy? \n";
return 0;


2.
1
2
cout << "You're a freelance? Good luck out there. \n";
return 0;


3.
1
2
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
return 0;

Thanks for the quick reply! I have re coded with your suggestions, however, once I come to the second input where I either must enter Sam or Frodo for LOTR or Rebels or Imperials for starwars, it reverts back to saying "You don't don't like either of them? Are you crazy?"
1.
else (movie != "Starwars" || movie != "Lordoftherings"); {

==>
else {

2.
else (side != "imperials" || side != "rebellion"); {

==>
else {

3.
else if (character != "Sam" || character != "Frodo"); {

==>
else {
Last edited on
Hi, so I made the changes and the code still doesn't seem to work as intended. I appreciate your patience.

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

#include <iostream>
using namespace std;

int main () 
{
	string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
	cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
	cin >> movie;
	
	

	if (movie == "Starwars") {
		cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
		cin >> side;
	}
	
	else if (movie == "Lordoftherings") {
		cout << "Who is your favourite character? Enter Sam or Frodo: \n";
		cin >> character;
		}
		
	else (movie != "Starwars" || movie != "Lordoftherings"); {
	cout << "You don't don't like either of them? Are you crazy? \n";
	return 0;
		}		

		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else (side != "imperials" || side != "rebellion"); {
			cout << "You're a freelance? Good luck out there. \n";
			return 0;
			}
	
	
	
	
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else if (character != "Sam" || character != "Frodo"); {
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			return 0;
			}
	
	
return 0;	
 	 
	
}



Last edited on
1.
else (movie != "Starwars" || movie != "Lordoftherings"); {

==>
else {

2.
else (side != "imperials" || side != "rebellion"); {

==>
else {

3.
else if (character != "Sam" || character != "Frodo"); {

==>
else {

P.S : Should I have to repeat this a second time?
Last edited on
I'm not sure what you mean by the sign "==>". If you could please explain that would be nice. I'm really sorry if I'm frustrating you.
"==>" is equivalent to "You change it to".
Last edited on
Ok I've made the changes you've suggested and it gets me farther into the program before spitting out two clauses. But, once I input the second question it spits out the "you must like Gimli the most" clause. Here it is with the changes in case I've messed something up again.

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

#include <iostream>
using namespace std;

int main () 
{
	string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
	cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
	cin >> movie;
	
	

	if (movie == "Starwars") {
		cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
		cin >> side;
	}
	
	else if (movie == "Lordoftherings") {
		cout << "Who is your favourite character? Enter Sam or Frodo: \n";
		cin >> character;
		}
		
	else {(movie != "Starwars" || movie != "Lordoftherings"); 
	cout << "You don't don't like either of them? Are you crazy? \n";
	return 0;
		}		

		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else {(side != "imperials" || side != "rebellion"); 
			cout << "You're a freelance? Good luck out there. \n";
			return 0;
			}
	
	
	
	
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else {
		(character != "Sam" || character != "Frodo"); 
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			return 0;
			}
			
		}
1
2
3
4
5
6
7
8
9
10
11
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else {
		(character != "Sam" || character != "Frodo"); 
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			return 0;
			}


Should be :
1
2
3
4
5
6
7
8
9
10
11
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else if (character.size() > 0){
		(character != "Sam" || character != "Frodo"); 
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			return 0;
			}
Alright, so with this input, the whole Starwars section works as intended. The only problem left that I face is that when I input my favourite character for lord of the rings it spits out "You're a freelance? Good luck out there."
1
2
3
4
5
6
7
8
9
10
		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else {(side != "imperials" || side != "rebellion"); 
			cout << "You're a freelance? Good luck out there. \n";
			return 0;
			}


Should be :
1
2
3
4
5
6
7
8
9
10
		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else if (side.size() > 0){(side != "imperials" || side != "rebellion"); 
			cout << "You're a freelance? Good luck out there. \n";
			return 0;
			}
Last edited on
The code is now working as intended. I have to thank you again for being super patient with me! Have a great rest of your night.
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
#include <iostream>
using namespace std;

int main () 
{
	string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
	cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
	cin >> movie;
	
	

	if (movie == "Starwars") 
	{
		cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
		cin >> side;
		
		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else (side != "imperials" || side != "rebellion"); {
			cout << "You're a freelance? Good luck out there. \n";
			}
	
	}
	
	else if (movie == "Lordoftherings") 
	
	{
		cout << "Who is your favourite character? Enter Sam or Frodo: \n";
		cin >> character;
		
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else if (character != "Sam" || character != "Frodo"); {
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			}
		}
		
	else 
	 {
		cout << "You don't like either of them? Are you crazy? \n";
		}		

	
	
	
	
	
return 0;	
 	 
	
}
@Benjidude
It does not look like your new program is free of errors.
Did you mess something up again?

@sabbirshawon
Edit : Your code does not work.
Last edited on
That's not my new code above. This is it:

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

#include <iostream>
using namespace std;

int main () 
{
	string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
	cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
	cin >> movie;
	
	

	if (movie == "Starwars") 
			{
		cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
		cin >> side;
			}
	
	else if (movie == "Lordoftherings") 
			{
		cout << "Who is your favourite character? Enter Sam or Frodo: \n";
		cin >> character;
			}
		
	else 	{
	(movie != "Starwars" || movie != "Lordoftherings"); 
	cout << "You don't don't like either of them? Are you crazy? \n";
	return 0;
			}		

		if (side == "imperials") {
			cout << "The dark side welcomes you. \n";
			}
		else if (side == "rebellion") {
			cout << "May the force be with you. \n";
			}
		else if (side.size() > 0){(side != "imperials" || side != "rebellion"); 
			cout << "You're a freelance? Good luck out there. \n";
			return 0;
			}
	
		if (character == "Sam") {
			cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
			}
		else if (character == "Frodo") {
			cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
			}
		else if (character.size() > 0)
			{
		(character != "Sam" || character != "Frodo"); 
			cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
			return 0;
			}

			
		}
	



Seems to be working just fine :)
Topic archived. No new replies allowed.