本文实例为大家分享了C语言实现随机出题测试计分的具体代码,供大家参考,具体内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int test();
int checknum( int a, int b);
int checkresult( int x);
int a = -1, b, c, x;
static int k = 0, grade;
void main() {
printf ( "请作答下列十道题,回车键开始开始作答!!!" );
getchar ();
do {
int i = test();
if (i == -1) {
break ;
}
else if (checkresult(i) == 0) {
a = -1;
}
} while (k);
getchar (); getchar (); getchar ();
}
int test() {
srand ((unsigned int ) time (NULL));
while (checknum(a, b) == 0)
{
a = rand () % 51;
b = rand () % 51;
c = rand () % 2;
}
k++;
if (k == 11) {
printf ( "答题结束,您本次测试总分是 %d ,谢谢" , grade);
return -1;
}
else if (c == 0) {
printf ( "第%d题: %d+%d=" , k, a, b);
return a + b;
}
else if (c == 1) {
printf ( "第%d题: %d-%d=" , k, a, b);
return a - b;
}
return -1;
}
int checknum( int a, int b) {
if ((a + b) > 50 || (a - b) < 0 || a > 50 || b > 50 || a < 0 || b < 0) {
return 0;
}
return 1;
}
int checkresult( int result) {
int i;
for (i = 1; i++; i <= 3) {
scanf_s( "%d" , &x);
if (x != result) {
if (i == 4) {
if (c == 0) {
printf ( "三次回答错误,正确答案是%d,请回答下一题\n" , a + b);
}
else {
printf ( "三次回答错误,正确答案是%d,请回答下一题\n" , a - b);
}
return 0;
}
printf ( "回答错误,请重新计算并输入结果:" );
}
else {
switch (i) {
case 2:
grade += 10;
break ;
case 3:
grade += 7;
break ;
case 4:
grade += 5;
break ;
default :
grade += 0;
break ;
}
return 0;
}
}
return 0;
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/zkd758/article/details/80210270