#实现猜数游戏#
/*程序功能:实现猜两个数,而且每一个数最多猜三次*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n=0,guess=0, magic = 0,conster=0/*计算器计数变量(conster),n(猜数的个数),guess(你所要猜的数)
magic(input)*/;
printf("input math sum:n=\n");
scanf_s("%d", &n);
while (n <= 2 ) {/*可以控制猜数的个数*/
srand((unsigned)time(NULL));/*实现随机数*/
magic = rand() % 100 + 1;/*实现随机数*/
do {
printf("input magic:\n");
scanf_s("%d", &guess);
conster++;
if (guess > magic)
printf("Wrong!Too high!\n");
else if (guess < magic)
printf("Wrong!Too low!\n");
else
printf("You Right\n");
} while (guess != magic&&conster<3);/*可控猜的次数*/
}
printf("一共猜了%d次\n", conster);
system("pause");
return 0;
}