Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;基本的;问卷游戏“;混淆错误_C++_Printing_Conditional - Fatal编程技术网

C++ C++;基本的;问卷游戏“;混淆错误

C++ C++;基本的;问卷游戏“;混淆错误,c++,printing,conditional,C++,Printing,Conditional,基本上,这个程序应该根据一个神秘的TA简单的是和否回答来询问用户。最后,用户被要求通过输入他们的名字来猜测TA是谁,如果名字是正确的,那么应该打印出来。然而,无论我输入什么作为猜测,我都会得到相同的输出 我的条件句有问题吗?资料来源如下: #include <iostream> #include <string> using namespace std; /* define global variabless about TA */ string name = "Con

基本上,这个程序应该根据一个神秘的TA简单的是和否回答来询问用户。最后,用户被要求通过输入他们的名字来猜测TA是谁,如果名字是正确的,那么应该打印出来。然而,无论我输入什么作为猜测,我都会得到相同的输出

我的条件句有问题吗?资料来源如下:

#include <iostream>
#include <string>
using namespace std;

/* define global variabless about TA */
string name = "Connor";

/* set all these as false until they get them right */
bool hairRight = false;
bool gfxArts = false;
bool ownsCat = false;
bool isJunior = false;
bool isGirl = false;
int score = 0;
string answer = ""; //used for user input
void questions()
{
    /* declare local variables */
    bool got_it = false; //right or wrong

    /* start loop */
    do {
        /* Pronmpt user */
        cout << "Does the TA have brown hair? Enter (Y) or (N)" << endl;
        cin >> answer;

        if ( answer == "Y" || answer == "y" ){
                cout << "Yes, you are correct!" << endl;
                hairRight = true; //set answer to correct
                score += 1;
            }else if ( answer == "N" || answer == "n"){
                cout << "I'm sorry, you are incorrect." << endl;
                got_it  = false;
            }else{
                cout << "Oops! I think you mispressed a button!" << endl;
            }

        cout << "Does the TA enjoy graphic design? Enter (Y) or (N)" << endl;
        cin >> answer;

        if ( answer == "Y" || answer == "y" ){
                cout << "Yes, you are correct!" << endl;
                gfxArts = true; //set answer to correct
                score += 1;
            }else if ( answer == "N" || answer == "n"){
                cout << "I'm sorry, you are incorrect." << endl;
                got_it = false;
            }else{
                cout << "Oops! I think you mispressed a button!" << endl;
            }

        cout << "Does this particular Ta enjoy programing?/ does this ta have have a cat? Enter (Y) or (N)" << endl;
        cin >> answer;

        if ( answer == "Y" || answer == "y" ){
                cout << "As far as I know, that's a complete lie..." << endl;
                ownsCat = false; //set answer to correct
                score -= 1;
            }else if ( answer == "N" || answer == "n"){
                cout << "I'm sorry, you are incorrect." << endl;
                got_it  = false;
            }else{
                cout << "Oops! I think you mispressed a button!" << endl;
            }

        cout << "This specific TA is a junior. Enter (Y) or (N)" << endl;
        cin >> answer;

        if ( answer == "Y" || answer == "y" ){
                cout << "Yes, you are correct!" << endl;
                isJunior = true;
                score += 1;
            }else if ( answer == "N" || answer == "n" ){
                cout << "I'm sorry, you are incorrect." << endl;
                got_it = false;
            }else{
                cout << "Oops! this TA has dark brown hair. good try though. " << endl;
            }

        cout << "Who is this mystery TA?" << endl;
        cin >> answer;

        if(got_it == true){
            cout << "Yes, you got it right!" << endl;
            cout << "Score: " << score << "/5" << endl;
        }else {
        cout << "Nope, you're wrong." << endl;
        cout << "Score: " << score << "/5" << endl;
        cout << "Press Enter to Restart" << endl;
        }


        } while (got_it == false);
            /* tell user he/she is wrong */
}

int main()
{
    questions();
    return 0;
}

你在哪里把它设定为真的?我哪儿都看不到。@jeffcarey你说得对。我现在就修好。但即使有第二个条件,我提供它仍然不起作用。无论输入如何,返回正确值
    cout << "Who is this mystery TA?" << endl;
cin >> answer;

if(got_it == true){
    cout << "Yes, you got it right!" << endl;
    cout << "Score: " << score << "/5" << endl;
}else {
cout << "Nope, you're wrong." << endl;
cout << "Score: " << score << "/5" << endl;
cout << "Press Enter to Restart" << endl;
}


} while (got_it == false);
    /* tell user he/she is wrong */
if(name == "Connor" || name == "connor")