标签:功能 www stdin ++ style switch www. 错误 地址
引用地址:http://www.cnblogs.com/huyunjia1995/p/5283836.html
主要是在原有的基础上增加了判断对错的功能。
经修改后的代码:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #include <math.h> 5 6 int main() 7 { 8 int i = 0; 9 int n = 0; 10 int x = 0; 11 int type; 12 char flag; 13 int left, right; 14 float result1,result2; 15 printf("请输入要出的题目数量\n"); 16 scanf_s("%d", &n); 17 srand(unsigned(time(NULL))); 18 while (x<n) 19 { 20 type = rand() % 4; 21 left = rand() % 100; 22 right = rand() % 100; 23 switch (type) 24 { 25 case 0: 26 printf("%d + %d = ?\n", left, right); 27 result1 = left + right; 28 break; 29 case 1: 30 printf("%d - %d = ?\n", left, right); 31 result1 = left -right; 32 break; 33 case 2: 34 printf("%d * %d = ?\n", left, right); 35 result1 = left * right; 36 break; 37 case 3: 38 printf("%d / %d = ?\n", left, right); 39 result1 = (float)left / right; 40 break; 41 } 42 printf_s("请输入答案:"); 43 scanf_s("%f",&result2); 44 if (fabs(result1 - result2)<=1e-6) 45 { 46 printf_s("计算正确\n"); 47 } 48 else 49 { 50 printf_s("计算错误\n"); 51 } 52 53 54 i++; 55 while (i >= n) 56 { 57 58 printf("谢谢使用!\n"); 59 fflush(stdin); 60 getchar(); 61 return 0; 62 } 63 } 64 }
标签:功能 www stdin ++ style switch www. 错误 地址
原文地址:http://www.cnblogs.com/xiangyujojo/p/7523080.html