From df28df324470713e74e28808e4136d758a215bb6 Mon Sep 17 00:00:00 2001 From: "3497769744@qq.com" <3497769744@qq.com> Date: Fri, 11 Jan 2019 02:34:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E7=BB=88=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pupilTest/pupilTest.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pupilTest/pupilTest.cpp b/pupilTest/pupilTest.cpp index 4cc3f5c..1a5c470 100644 --- a/pupilTest/pupilTest.cpp +++ b/pupilTest/pupilTest.cpp @@ -1,6 +1,6 @@ -#include "pch.h" + #include -#include //包含_gentch()函数,可以自动从缓冲区读取一个字符(不需要按回车) +#include //包含_getch()函数,可以自动从缓冲区读取一个字符(不需要按回车) #include //包含随机数函数 #include //包含时间函数 @@ -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) {