将零放在前面时,为什么我的小作弊代码不起作用。当我将零取出并放入小作弊代码后,它就可以正常工作了。但是,当我输入零并使用作弊代码时,它将立即跳过。

#include <iostream>
#include <random>

int main() {
    bool correct = false;
    std::cout << "Put a Number from 1 to 100" << std::endl;
    int guess = 0;
    std::cin >> guess;
    std::random_device rd;
    std::mt19937 mt(rd());
    std::uniform_int_distribution<int> rnd(0, 101);
    int answer = rnd(mt); //random number
    while (correct == false)
    {
        if (guess == answer)
        {
            std::cout<<"You got it!!!"<<std::endl;
            correct = true;
        }
        else if (guess == 01010101)#<--------------------Problem
        #it works when it is 1010101
        {
            std::cout<< answer<< std::endl;
            std::cout << "Put a Number from 1 to 100" << std::endl;
            std::cin >> guess;
        }
        else if (guess > answer)
        {
            std::cout<<"Your guess is to high guess again"<< std::endl;
            std::cout << "Put a Number from 1 to 100" << std::endl;
            std::cin >> guess;
        }
        else if (guess < answer)
        {
            std::cout<<"Your guess is to low guess again"<< std::endl;
            std::cout << "Put a Number from 1 to 100" << std::endl;
            std::cin >> guess;
        }

        else
        {
            std::cout << "Put a Number from 1 to 100" << std::endl;
            std::cin >> guess;
        }


    }
}

最佳答案

数字文字上的前导零表示该文字以octal(基数8)表示法1表示,该符号(显然)的大小与解释为十进制的相同数字(基数10)不同。

八进制数字01010101等于十进制数字266305。

1除非前导零后面跟着x,否则它将被解释为十六进制(以16为底)。

09-12 10:43