user-0 提问: 求大佬帮帮小白吧

回复:
user: user-1
content: 按照你的需求写个简单的例子，随机生成的题。 只是小学生除法不知道到什么程度，是用分数表示还是小数，所以除法部分LZ再修改吧。  typedef struct expr {     double num1;     double num2;     char opt;     double answer1;     double answer2;     int result;     expr *next; } EXPR, *PEXPR;  typedef struct ques {     PEXPR expr;     int count;     int right; } QUES, *PQUES;  char opts[4] = {'+', '-', '*', '/'};  PQUES pQ;  void genQues() {     if (pQ==NULL) {         srand(time(NULL));         pQ = (PQUES)malloc(sizeof(QUES));         pQ->count = 0;         pQ->right = 0;     }     int tmp = 0;     PEXPR exp = (PEXPR)malloc(sizeof(EXPR));     exp->num1 = rand()%10;     exp->num2 = rand()%9 + 1;     exp->opt = rand()%4;     exp->next = NULL;     switch (exp->opt) {         case 0:             exp->answer1 = exp->num1 + exp->num2;             break;         case 1:             if (exp->num1 > exp->num2) {                 tmp = exp->num1;                 exp->num1 = exp->num2;                 exp->num2 = tmp;             }             exp->answer1 = exp->num1 - exp->num2;             break;         case 2:             exp->answer1 = exp->num1 * exp->num2;             break;         case 3:             exp->answer1 = exp->num1 / exp->num2; //除法根据需要修改         default:             break;     }     exp->result = 0;     if (pQ->count > 0) {         exp->next = pQ->expr;     }     pQ->expr = exp;     pQ->count++; }   int main(int argc, const char * argv[]) {     char Y = 'Y';     PEXPR exp;     while (Y == 'Y' || Y == 'y') {         genQues();         printf("%.0f%c%.0f=?\n", pQ->expr->num1, opts[pQ->expr->opt], pQ->expr->num2);         scanf("%lf", &pQ->expr->answer2);         getchar();         if (pQ->expr->answer2==pQ->expr->answer1) {             pQ->expr->result = 1;             pQ->right++;             printf("Right!\n");         } else {             printf("Wrong!\n");         }         printf("是否继续答题？继续答题输入Y，退出输入N\n");         Y = getchar();     }     printf("总共答题%d，做对%d题，分数%.0f\n", pQ->count, pQ->right, 100.0*pQ->right/pQ->count);     while(pQ->expr!=NULL) {         exp = pQ->expr->next;         free(pQ->expr);         pQ->expr = exp;     }     free(pQ);     return 0; }

user: user-2
content: /*************************************************************************     > File Name: abb.cpp     > Author: cfjtaishan     > Mail: cfj20080302@163.com      > Created Time: 2020年03月18日 星期三 20时29分46秒  ************************************************************************/  #include <stdio.h> #include <math.h>  float get_result(float a, char opt, float b);  int main(void) { 	char opt1, opt2; 	float a, b, c, result; 	int choice;  	printf("Please input your choice: (1: two number opt, 2: three nubers opt)"); 	scanf("%d", &choice);  	if (choice != 1 && choice != 2) { 		printf("Input error!\n"); 		return -1; 	}  	if (choice == 1) { 		printf("Please input your operation: (eg: 1*2)"); 		scanf("%f%c%f", &a, &opt1, &b); 		printf("=%.2f\n", get_result(a, opt1, b)); 		return 0; 	} 	printf("Please input your operation: (eg: 1*2*3)"); 	scanf("%f%c%f%c%f", &a, &opt1, &b, &opt2, &c); 	if (opt1 == '*' || opt1 == '/') { 		result = get_result(a, opt1, b); 		printf("=%.2f\n", get_result(result, opt2, c)); 	} else if (opt2 == '*' || opt2 == '/') { 		result = get_result(b, opt2, c); 		printf("=%.2f\n", get_result(a, opt1, result)); 	}  	return 0; }   float get_result(float a, char opt, float b) { 	float result;  	switch (opt) { 		case '+':  			result = a+b; 			break;  		case '-': 			result = a-b; 			break;  		case '*': 			result = a*b; 			break;  		case '/': 			if (fabsf(b) > 1e-6) 				result = a/b; 			break; 	}  	return result; }  供参考～  虽然不是完全符合要求，建议在这个基础上可以改一改。