Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ returning bool is always false?
    primarykey
    data
    text
    <p>I implemented a Quiz Code and did a short change at the end of it to check if the User answered it correctly. </p> <p>My if / else looks like this: </p> <pre><code> if (answer == rightanswer){ rightA = true; } else { rightA = false; } return rightA; </code></pre> <p>I already checked with the debugger that if the correct answer is entered it goes to rightA = true; and to return, so this works finde. But if i check the value of rightA it's false. If it's needed, here is the function that i use to call the Quiz:</p> <pre><code>void gameOver(char field[HEIGHT][WIDTH], char newField[HEIGHT][WIDTH]){ // TODO bool rightA = false; showQuizDialog(rightA); do{ system("cmd /c cls"); switch (rightA){ case true : cout &lt;&lt; "menu"; menu(field, newField); break; case false : showQuizDialog(rightA); break; default : cout &lt;&lt; " "; } }while(rightA == false); } </code></pre> <p>I'm a bit hintless. I may have some logic failure in it i just don't see at the moment. Greetings</p> <p>E: I don't wanted to bomb you guys with code. But here is it: </p> <pre><code>bool showQuizDialog(bool rightA){ Quiz* quiz = Quiz::getInstance(); quiz -&gt; askQuestion(rightA); return rightA; } </code></pre> <p>And the full askQuestion:</p> <pre><code> bool Quiz::askQuestion(bool rightA) { int fragenID = rand() % this-&gt;fragen.size(); //zufällige Fragen auswählen struct Question frage = this-&gt;fragen.at(fragenID); std::cout &lt;&lt; frage.frage.c_str() &lt;&lt; std::endl &lt;&lt; endl; //Frage stellen int rightanswer = this-&gt;listAnswers(frage.antworten); int answer = this-&gt;readAnswer(0, frage.antworten.size() - 1); if (answer == rightanswer){ rightA = true; } else { rightA = false; } return rightA; } </code></pre>
    singulars
    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.
    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