Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ - An if statement checking strings improperly
    primarykey
    data
    text
    <p><Code></p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; string questionOneAnswer; string questionTwoAnswer; string questionThreeAnswer; class quizAshton{ public: string question1(){ cout &lt;&lt; "What is your favorite food?" &lt;&lt; endl; cin &gt;&gt; questionOneAnswer; return questionOneAnswer; } string question2(){ cout &lt;&lt; "What is the name of someone you hate?" &lt;&lt; endl; cin &gt;&gt; questionTwoAnswer; return questionTwoAnswer; } string question3(){ cout &lt;&lt; "Hi! (yes or no)" &lt;&lt; endl; cin &gt;&gt; questionThreeAnswer; return questionThreeAnswer; } }; int main() { quizAshton ashtonAnswers; ashtonAnswers.question1(); ashtonAnswers.question2(); ashtonAnswers.question3(); if (questionThreeAnswer!= "yes" or "no"){ cout &lt;&lt; "I asked for a yes or no! You betrayed me!" &lt;&lt; endl; return 0; } cout &lt;&lt; "APPARENTLY your favorite food is " &lt;&lt; questionOneAnswer &lt;&lt; "... I guess I wouldn't really believe that unless it was eaten by " &lt;&lt; questionTwoAnswer &lt;&lt; "and is the cat ready...: " &lt;&lt; questionThreeAnswer &lt;&lt; endl; return 0; } </code></pre> <p></Code></p> <p>The "if" statement under main, even if I put yes or no or an invalid answer, will still continue the if statement. (no matter what I put, it will still display the message inside the if statement).</p> <pre><code>if (questionThreeAnswer!= "yes" or "no"){ cout &lt;&lt; "I asked for a yes or no! You betrayed me!" &lt;&lt; endl; return 0; } </code></pre> <p>I know this is a simple fix, but i'm not entirely sure what. I'm a bit of a noobie. Also, this may or may not be the most efficient way of doing what i'm trying to do, but this is mostly for practice.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload