help with rpg code

My header is a collection of all neccesary headers and using namespace std;
When I run this, it always says that my command is invalid no matter what I write.
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
#include "rpghead.h"

int state = 1;

void help();
void room1();

int main()
{
    cout<<"\nPlease do all typing in lowercase.\n";
    
    while(state != -1)
    {
        switch(state)
        {
            case 1:
                room1();
                break;
        }
    }
}

void room1()
{
    string action;
    
    cout<<"\nYou wake up with no recollection of who you are. You sit up and look around. It apears to be a small, square room about 20 ft. by 20 ft. by 20 ft. Besides the thin cot you are sleeping on, there is a round, wooden table and a chest at the foot of the cot. There is a door on the west wall. There are no windows. The four walls are made completely out of stone. What do you want to do (type \"help\" for a list of commands)?\n>";
    getline(cin, action);
    
    if(action != "help" || action != "open door" || action != "open chest")
    {
        while(action != "help" || action != "open door" || action != "open chest")
        {
            cout<<"\nThat is not valid. What do you want to do?\n>";
            getline(cin, action);
        }
    }
    
    if(action == "help")
    {
        help();
    }
    
    if(action == "open door")
    {
        cout<<"\nYou open it and find yourself staring at a brick wall. There must be another way out. What do you want to do?\n>";
        getline(cin, action);
        
        if(action != "help" || action != " open chest")
        {
            while(action != "help" || action != " open chest")
            {
                cout<<"\nThat is invalid. What do you want to do?\n>";
                getline(cin, action);
            }
        }
    }
    
    if(action == "help")
    {
        help();
    }
    
    if(action == "open chest")
    {
        cout<<"\nInside the chest you find:\n-50 gold\n-a rusty short sword\n-a backpack\n\nSuddenly, a false door on the east wall is opened. An orc with what appears to be an axe in his hand, steps into the room with an intent to kill you.";
    }
}

void help()
{
    cout<<"\nCommands:\n-open door\n-open chest\n";
    
    return;
}
(action != "help" || action != " open chest")

Can you think of ANY value for action, for which this comes out as false? No, you can't, because there isn't one. This will ALWAYS come out as true. I suspect you meant to say

(action != "help" && action != " open chest")
oh that makes sense thank you
so i fixed that and now it says "invalid operands to binary expression ('bool' and 'string' (aka 'basic_string<char>))" Im not even going to pretend like i no what that means
nvr mind i fixed it
new problem when I type in help it will list it all twice why?
Last edited on
Because you have this code twice:

1
2
3
4
  if(action == "help")
    {
        help();
    }

duh i am not at my smartest tonite i forgot to delete the second one when I moved it
Topic archived. No new replies allowed.