打字游戏代码

#include<windows.h>
#include<iostream>
using namespace std;

struct timevale
{
long tv_use;//以秒为单位

long tv_usec;//以毫秒为单位
}current_time;


int main()
{
int start_outchar;

char outchar;
char inchar;


while(1)
{
start_outchar=34;
long time=GetTickCount();
current_time.tv_usec=time;
srand(time);//GetTickCount/time它返回从操作系统启动到当前所执行经过的毫秒
start_outchar+=rand()%105;//随机读取键盘105个字母

outchar=start_outchar;
cout<<outchar<<endl;
cin>>inchar;
if(inchar==outchar)//判断输出字符与输入字符是否相等
{
time=GetTickCount();
cout<<"你用时间:"<<time-current_time.tv_usec<<"毫秒"<<endl;
}
else if(inchar!=33)
{
cout<<"你出错了"<<"\a"<<endl;
}
else
break;
}
return 0;
}

posted on 2012-03-14 22:53  fengshaohua  阅读(380)  评论(0)    收藏  举报