Trouble with if/else using strings

Hi, first post here. I'm a relative noobie when it comes to c++ but I've been learning for a few months now and decided to make a game. So, the problem I'm having is, when it gets to the section of the code where the character is prompted to feel around on the left or the right, no matter what option the user chooses it displays the outcomes for all of them(including the invalid character option).
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <istream>

using namespace std;

int main()
{
string mystr;                               //declaring variables
std::string nameevil;                      //for user input and output
string name;
char tf;                                  // Boolean true false (A HA!)
string bm;

    cout << " <<<>>> DEATH BRINGER 49 <<<>>> " << endl;                             //Title screen
    cout << " ****************************** " << endl;
    cout << " A text based adventure game by Nicholas jeffs " << endl;
    cout << " ****************************** " << endl;
    cout << " ****************************** " << endl;
    cout << endl;
    cout << endl;
    cout << endl;
    cout << " Every hero needs a name! Enter your name to start the game. " << endl;
    cout << " ******************************* "  << endl;
    getline (cin, name) ;                                                              // assigns value to string name
    cout << " Alright " << name << " are you prepared to start the game? (type y or n) " << endl;
  cin >> tf;
   if (tf == 'y' || tf == 'Y' )
  {
   cout << " Remember, keep your wits about you and youll be fine! (PRESS ENTER) " << endl;
 cin.ignore();
  cin.get();
    cout << string(50, '\n');  // gives illusion of clearing screen by going down 50 lines
   

  }
   else
    { 
    cout << " Too afraid? Come back when you have courage!(Press enter to exit) " << endl;
    cin.ignore();
    cin.get();
    return 0;
    }
    cin.get();
      cout << string(50, '\n');  // gives illusion of clearing screen by going down 50 lines
   
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " ( You are surrounded by darkness ) " << endl;
    cout << " ( You hear a sinister voice, but cant pinpoint its location ) " << endl;
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " *Hello "  << name << " ....... " << endl;
    cout << " *Yes we know your name " << endl;
    cout << " *Yes, as you know ours..... tell me, what is our name in your tounge? " << endl;
  cin >> nameevil ;
  
  cout << endl;
  cout << endl;
    cout << " *Ah, " << nameevil << " is it ? " << endl;
    cout << " *Well then..... It is us, " << nameevil << ". We decided to play some games! " << endl;
    cout << " *Just like we used to in your dreams, " << endl;
    cout << " *dont pretend you could ever forget, ever... " << endl;
    cout << " *Ill be dropping you into my inter dimensional death trap." << endl;
    cout << " *You will have to find a way out, or die in the maze.. " << endl;
    cout << " *The choice is yours, good luck (Snicker snicker ) " << endl;
    cout << " * Whoops, almost forgot. Any message from me will be preceded with a * " << endl;
    cout << " * Ill be keeping an eye on you, bon voyage! (PRESS ENTER) " << endl;
    cin.ignore();
    cin.get();
    cout << string (50, '\n');
    
    cout << " Chapter one: Immobilized " << endl;
    cout << " ****************************** " << endl;
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " ( You feel the ground dissapear beneath your feet and begin to plumit rapidly ) " << endl;
    cout << " ( Above is the harsh kackling of " << nameevil << ", below an unknown fate ) " << endl;
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << "." << endl;
    cout << " ." << endl;
    cout << "  . NOOOOOOOOOOOOO..." << endl;
    cout << "   . OOOOOOOO" << endl;
    cout << "    .AHHHHH" << endl;
    cout << "    .HHH...... " << endl;
    cout << "   . " << endl;
    cout << "  . " << endl;
    cout << " . " << endl;
    cout << ". *THUD" << endl;
    cout << " PRESS ENTER TO WAKE UP!!!! " << endl;
    cin.ignore();
    cin.get();
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " ------------- " << endl;
    cout << " ( You awake hours later in a pitch black room. The only features you ) " << endl;
    cout << " ( can make out are the stench of fetided stagnant water, ) " << endl;
    cout << " ( and the sound of your own screams. Both your legs are broken and you must ) " << endl;
    cout << " ( crawl to survive. Try and search the immediate area for usefull items ) " << endl;
    cout << endl;
    cout << endl;
    tryagain: 
 
    cout << " Type left to feel around on your left, and right to feel around on your right " << endl;
    cin >> bm;
   {
        if (bm == "Left" || "left")
    {
    cout << " You find a jaged peice of glass, could be useful " << endl;
    cout << endl;
    cout << " ^^GLASS ADDED TO INVENTORY^^ " << endl; }
    else 
    cout << "Invalid input " << endl;
   
     
   if ( bm == "Right" || "right" )
    {
    cout << " You find an old 2x4, perfect for a makeshift crutch! " << endl;
    cout << endl;
    cout << " ^^CRUTCH ADDED TO INVENTORY^^ " << endl; 
    }
   
    else
    cout << " Invalid input " << endl;
   
    }
 
    cin.get(); // stops program from automatically closing once run
    return 0;
 }


Any other tips on fixing my terrible code would be appreciated also!
bm == "Left" || "left" should be bm == "Left" || bm == "left" (same for right)
Last edited on
Topic archived. No new replies allowed.