master
3497769744@qq.com 7 years ago
parent d7e56ae723
commit df28df3244

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

Loading…
Cancel
Save