⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guess.c

📁 猜字游戏
💻 C
字号:
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>
#include <windows.h>

void main(void)
{
	int answer[4];
	int guess;
	int a=0, b=0;
	int i=0, j=0;
	int times=0;
	char temp='Y';
	
//	printf("DO you want to continue?(Y\N)");
//	temp = getchar();
	while ((temp == 'Y')||(temp == 'y'))
	{
		times = 0;
		a=0, b=0;
		for (i=0; i<=3; i++)
		{
			srand( (unsigned)time( NULL ) );
			answer[i] = rand() % 10;
			for (j=0; j<i; j++)
			{
				while (answer[i] == answer[j])
				{
					answer[i] = rand() % 10;
					j = -1;
				}
			}
		}

		printf("Please guess!\n");

		while (a!=4)
		{
			a = 0; 
			b = 0;
			times++;
			do{
				printf("%d		", times);
				scanf("%d", &guess);
				if (guess == 0)
					exit(0);
			}while(guess<0 || guess>9999);

			for (i=3; i>-1; i--)
			{
				for (j=0; j<4; j++)
				{
					if ((int)(guess/pow(10,i)) == answer[j])
					{
						if (i+j==3) 
							a++;
						else b++;
					}
				}
				guess = guess - (int)(guess/pow(10,i)) * pow(10, i);
			}
			printf("		%dA%dB\n", a, b);
		}
	getchar();
	printf("DO you want to continue?(Y/N)\n");
	temp = getchar();
	getchar();
	}
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -