-1

I just started learning C++ and am working on making a small game template thing for a text based adventure game and wanted some help with 2 things. One of those would be excluding answers, and the other making new questions pop up after one is answered and the output is given. I would consult the creator of the tutorial I was watching, but he never made it past part 2 and hasn't touched his youtube channel in 3 years. I tried taking the answers and replacing the input thing with =! instead of ==. I've been using an online compiler (http://cpp.sh) for faster editing, so here is the crash log for that:

23:25: error: no match for 'operator||' (operand types are 'bool' and 'std::string {aka std::basic_string<char>}') 23:25: note: candidate is: 23:25: note: operator||(bool, bool) <built-in> 23:25: note: no known conversion for argument 2 from 'std::string {aka std::basic_string<char>}' to 'bool' 23:43: error: no match for 'operator||' (operand types are 'bool' and 'std::string {aka std::basic_string<char>}') 23:43: note: candidate is: 23:43: note: operator||(bool, bool) <built-in> 23:43: note: no known conversion for argument 2 from 'std::string {aka std::basic_string<char>}' to 'bool' 23:60: error: no match for 'operator||' (operand types are 'bool' and 'std::string {aka std::basic_string<char>}') 23:60: note: candidate is: 23:60: note: operator||(bool, bool) <built-in> 23:60: note: no known conversion for argument 2 from 'std::string {aka std::basic_string<char>}' to 'bool'

And this is my code:

#include <iostream>
using namespace std;

int main(int argc, char *argv[]){
    string input;
    int hp = 100;
    int finalhp;
    cout << "Your HP: " << hp << endl;
    cout << "Walking in the DANK castle dungeon, you stumble upon a dying man. Would you like to finish him off?\n1. Yes\n2. No" << endl;
    cin >> input;
    if (input == "yes" || input == "Yes") {

        finalhp = hp - 5;
        cout << "You monster, you should have helped him. You are attacked by guilt. -5 HP. You are now at:" << finalhp << endl;
    }
    else if (input == "no" || input == "No"){

        finalhp = hp + 5;
        cout << "You spared the man's life. While he sits there peacefully recovering, he gives you a potion giving you 5 hp. You are now at: " << finalhp << endl;

    }

else if (input =! "yes" || input =! "Yes" || input =! "no" || input =! "No"){

        cout << "Quit babbling like an idiot and answer my question!";

        return 0;
    }

}

Any help would be great!

2 Answers2

0

Numerous typos.

input =! "yes" || input =! "Yes" || input =! "no" || input =! "No"
      ^^                ^^                ^^               ^^

should be

input != "yes" || input != "Yes" || input != "no" || input != "No"

If you look at operator precedence, the expression

input =! "yes" || input =! "Yes" || input =! "no" || input =! "No"

would be quite crazy, not the simple expression that you were thinking of.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
0

=! is not an operator in C++. The not-equal-to operator is !=. Because of this, your last else if condition is not doing what you think it is. It's basically doing

input = (!"yes" || input = (!"Yes" || input = (!"no" || input = !"No")))

which leads to your error about no operator||(bool, std::string) existing.

Miles Budnek
  • 28,216
  • 2
  • 35
  • 52