为什么我的小作弊码在我面前放零时不起作用。当我取出零并将小作弊码放入其中时工作得很好。但是,当我把零输入并使用作弊码时 - 它会跳过它。
#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;
}
}
}
答案 0 :(得分:14)
数字文字的前导零表示文字以octal(基数8)表示法 1 表示,其(显然)具有与解释为的相同数字不同的数字十进制(基数为10)。
八进制数01010101等于十进制数266305。
1 除非前导零后跟x
,否则它被解释为十六进制(基数为16)。