CPP 猜谜游戏不工作,在我输入名字后停止

CPP Guessing Game not working, its stops after i enter the name

我正在尝试在 C++ 上制作这个基纳猜谜游戏,我是初学者,仍在学习中。 我想要实现的是两个 const 名称的猜谜游戏,非常简单,没有错误,但在我输入内容后它不起作用。它应该报告,直到我找到正确的名字。也请我不想改变代码的结构,只是找出为什么不工作。

#include <iostream>
#include <string>
using namespace std;
struct Vlerat {
    string guess01 = "Resul";
    string guess02 = "Rejan";
    int numruesi = 0;
};

int main() {
    Vlerat funksioni;
    string nameGuess;
    int nameOkay = 0;
    cout << "Gjej njerin prej dy emrava te fshehura." << endl;
    cout << "Ndihm: Fillojn me Shkronjen 'R', dhe pas asaj vjen edhe nje shkronj 'e'" << endl;
    do {
        cout << "Shkruaj Emrin > "; cin >> nameGuess;

        if (nameGuess == funksioni.guess01){
            cout << "Ju e keni gjetur emrin e njerit nga personat duke provuar gjithesej:";
            cout << funksioni.numruesi++ << " here." << endl;
            nameOkay++;
        }
        if (nameGuess == funksioni.guess02) {
            cout << "Ju e keni gjetur emrin e njerit nga personat duke provuar gjithesej:";
            cout << funksioni.numruesi++ << " here." << endl;
            nameOkay++;
        }
        funksioni.numruesi++;
    } while(nameOkay = 0);
}

您应该将 while(nameOkay = 0); 更改为 while(nameOkay == 0);。 因为 = 是赋值,而 == 是比较运算符(相等)

Read about it here

And here