|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
#include "pch.h"
|
|
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<conio.h> //包含_gentch()函数,可以自动从缓冲区读取一个字符(不需要按回车)
|
|
|
|
|
#include<conio.h> //包含_getch()函数,可以自动从缓冲区读取一个字符(不需要按回车)
|
|
|
|
|
#include<stdlib.h> //包含随机数函数
|
|
|
|
|
#include<time.h> //包含时间函数
|
|
|
|
|
|
|
|
|
@ -8,25 +8,38 @@ int main()
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
srand(time(NULL)); //time(NULL)读取得到从标准计时点(一般是1970年1月1日午夜)到当前时间的秒数。
|
|
|
|
|
//srand()是随机数发生器的初始化函数
|
|
|
|
|
int x, y, score = 0, count = 0, correctAnswer, currentAnswer, flag;
|
|
|
|
|
//x:前一个数,y:后一个数,score:最终分数,count:答题次数,correntAnswer:正确答案,currentAnswer:当前答案 ,flag:临时量
|
|
|
|
|
char choice,op;
|
|
|
|
|
|
|
|
|
|
//choice:存储选择,op:运算符
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
|
|
printf("欢迎进入测验,电脑将随机出10道题,每道题有三次作答机会,但每答错一次对应分数就会减少\n");
|
|
|
|
|
|
|
|
|
|
printf("按Enter键进入考试,其他键退出");
|
|
|
|
|
|
|
|
|
|
choice = _getch();
|
|
|
|
|
|
|
|
|
|
if (choice == 13) //Enter键的ascii码
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
system("cls"); //清屏
|
|
|
|
|
|
|
|
|
|
printf("现在是第%d道题:\n",i + 1);
|
|
|
|
|
|
|
|
|
|
x = rand() % 51; //产生0~50的随机数
|
|
|
|
|
|
|
|
|
|
flag = rand() % 2; //flag为0或1
|
|
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
op = '+';
|
|
|
|
|
}
|
|
|
|
@ -51,7 +64,7 @@ int main()
|
|
|
|
|
printf("第%d次作答\n", j + 1);
|
|
|
|
|
count++;
|
|
|
|
|
printf("请输入您的答案:");
|
|
|
|
|
scanf_s("%d", ¤tAnswer);
|
|
|
|
|
scanf("%d", ¤tAnswer);
|
|
|
|
|
|
|
|
|
|
if (currentAnswer == correctAnswer)
|
|
|
|
|
{
|
|
|
|
|