简单的练习打字游戏

#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<corecrt.h>
void help()
{
	printf("\n******************************************");
	printf("\n**********输入过程中无法退出操作**********");
	printf("\n**********请按所给字母敲击键盘************");
	printf("\n**请按任意键开始测试,按下首字母开始计时**");
	printf("\n**********输入出错请以任意键结束**********");
	printf("\n****************************************** ");
	printf("\n\n");
}
int main()
{
	char ch;
	char str[51] = "";
	
	int i=0;
	int count;
	time_t start_time=0, end_time=0;
	int waste_time;
	while (1)
	{
		system("cls");
		help();
		ch = _getch();
		if (i == 0)
		{
			start_time = time(NULL);
		}
		srand((unsigned)time(NULL));
		for (i = 0; i < 50; i++)
		{
			str[i] = rand() % 26 + 'a';
		}
		str[50] = '\0';
		printf("%s\n", str);
		count = 0;
		for (i = 0; i < 50; i++)
		{
			ch = _getch();
			if (ch == str[i])
			{
				count++;
				printf("%c", ch);
			}
			else
			{
				printf("_");
			}
		}
		end_time = time(NULL);
		waste_time = end_time - start_time;
		printf("\ncount=%d\n", count);
		printf("正确率为:%d%c\n", count * 100 / 50, '%');
		printf("总共消耗的时间为%lld秒\n", (long long int)waste_time);
		while (1)
		{
			ch = _getch();
			if (ch == ' ')
				break;
			if (ch == 27)
				return 0;
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值