-2
#include <iostream>

using namespace std;

int main(){

    cout << endl;
    cout << "Welcome to the wonderful world of a spy" << endl;
    cout << "Today we are to decode some information that has been provided." <<endl;
    string response;
    cout << "Are you ready?" << endl;
    cin >> response;
    if (response == "yes", "y", "Yes", "Y"){
        cout << "Alright, let's go!!!" << endl;
    }
    else {
        cout << "Well, too bad. We are going to do it anyways." << endl;
    }
}

Exact Code Here is my code thus far. I can't get it to not say "Alright, let's go!!! What am I doing wrong?

James Adkison
  • 9,412
  • 2
  • 29
  • 43
WinryKate
  • 35
  • 7
  • 2
    Let's start with an actual code snippet, not a screenshot. Please paste the code into your question. –  Sep 26 '17 at 19:43
  • 5
    Please don't try to guess the syntax. The result of that `if` statement is the evaluation of `"Y"`, which is always `true` (the rest is discarded, they have no side effects). Please get a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Rakete1111 Sep 26 '17 at 19:43

2 Answers2

4

The line if (response == "yes", "y", "Yes", "Y") doesn't do what you think it does. The comma operator evaluates each of its operands, discards the result on the left and takes the result on the right as the result of the expression. So what you wrote is equivalent to if ("Y"). You need to use the logical OR operator to combine your different cases. Like this if (response == "yes" || response == "y" || response == "Yes" || response == "Y").

Peter Ruderman
  • 12,241
  • 1
  • 36
  • 58
3

your if statement conditions are wrong.

    if(response == "yes" || response == "y" || response == "Yes" || response == "Y")
    {
        //then do whatever...
    }else{
        //do it anyway...
    }
kman123
  • 140
  • 1
  • 7