# C++猜数字（文曲星游戏）

#include<iostream>
#include<ctime>
#define MaxIndex 10000
using namespace std;

//产生随机数
int Random() {
srand((unsigned)time(NULL));
int index = (int)rand() % MaxIndex;
return index;
}

//赋值
void fuzhi(int *A,int x) {
for (int i = 0; i < 4; i++) {
int m = pow(10, 3 - i);
A[i] = x / m;
x = x%m;
}
}

//转换char到int
void Change(char *A, int *B) {
for (int i = 0; i < 4; i++) {
*(B + i) = (int)(*(A + i))-48;
}
}
//判断答案
int judge(int *A, int *B) {
int a = 0, b = 0;
for (int i = 0; i < 4; i++) {
if (*(A + i) == *(B + i)) {
a++;
}
else {
for (int j = 0; j < 4; j++) {
if (*(A + i) == *(B + j)) {
b++;
}
}
}
}
cout << a << "A" << b << "B" << endl;
return a - b;

}
int main() {
char B[4];
index = Random();
fuzhi(standard, index);
cout << index;

for (int i = 0; i < 8; i++) {
cout << "你共有八次机会";
cout << "请输入你的答案：";
for (int j = 0; j < 4; j++) {
cin >> B[j];
}
if (judge(standard, answer) == 4) {
cout << "恭喜你答对了！";
break;
}
else {
cout << "抱歉，你的答案错误！";
}

}
cout << "程序运行结束\a";
system("pause");
return 0;
}