C语言实现简单打字游戏 #include<stdio.h> #include<time.h> #define NUM 15 void test1(){ char s[NUM + 1] = {'0'}; srand((size_t)time(NULL)); //以下为计算正确率 int count = 0; //以下为记录用时 int startTime = 0; int endTime = 0; for (int i = 0; i < 15;i++) { s[i] = rand()%25+'a'; } printf("%s\n", s); for (int j = 0; j < 15;j++) { //getchar在这里不合适,有回显,而且需要按回车确认 //char c=getchar(); //_getch()则没有回显,而且不需要回车确认 char c = _getch(); if (j==0) { startTime = time(NULL); } //进行正确确认 if (s[j]==c) { printf("%c", c); count++; } else { printf("%c\a",'*'); } } printf("\n正确率为:%.2lf%%\n",(double)count/15*100); endTime = time(NULL); printf("用时%ds",endTime-startTime); } void main() { test1(); }