本文主要是介绍C语言程序设计苏小红课后习题答案7.14.6 计算机辅助教学,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//错误回答
int error()
{int type;type = rand() % 4 + 1;switch (type){case 1:return printf("No.Please try again.");case 2:return printf("Wrong. Try once more.");case 3:return printf("Don't give up!");case 4:return printf("Not correct. Keep trying.");default:return 0;}
}//回答正确
int correct()
{int type;type = rand() % 4 + 1;switch (type){case 1:return printf("Very good!");case 2:return printf("Excellent!");case 3:return printf("Nice work!");case 4:return printf("Keep up the good work!");default:return 0;}
}
//生成随机符号
char Charop()
{int op;op = rand() % 4 + 1;switch (op){case 1:return '+';case 2:return '-';case 3:return '*';case 4:return '/';}return 0;
}
//生成随机数(1到10)
int number()
{int a;a = rand() % 10 + 1;return a;
}
//运算
int Calculate(int x, char op, int y)
{int a, b, c, d;a = x + y;b = x - y;c = x * y;d = x / y;switch (op){case '+': return a;case '-': return b;case '*': return c;case '/': return d;default:return 0;}
}
//整合函数
int fun()
{int answer, counter = 0, grade = 0;int x, y, m, n;char op;for (int i = 1;i <= 10;i++){srand(time(NULL));x = rand() % 10 + 1;y = rand() % 10 + 1;op = Charop();printf("%d%c%d=", x, op, y);scanf("%d", &answer);if (answer == Calculate(x, op, y)){printf("%d\n",correct());grade++;}else{printf("%d\n", error());}counter++;}printf("grade=%d\n", grade);if (grade * 10 < 75){printf("Please again\n");return fun();}elsereturn 0;}
//主函数
int main()
{fun();return 0;
}
这篇关于C语言程序设计苏小红课后习题答案7.14.6 计算机辅助教学的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!