俩个数
#include <cstdio>
#include <stack>
#include <cstdlib>
#define MAXNUM 100
char fin_formula[50], ori_formula[50];
char op[4];
int ans, num[4];
void create() {
int flag = rand() % 4;
if(flag == 0) {
op[0] = ‘+‘;
num[0] = rand() % MAXNUM;
num[1] = rand() % MAXNUM;
ans = num[0] + num[1];
printf("%d + %d = ? \n", num[0], num[1]);
}
else if(flag == 1) {
op[0] = ‘-‘;
ans = rand() % MAXNUM;
num[1] = rand() % MAXNUM;
num[0] = num[1] + ans;
printf("%d - %d = ? \n", num[0], num[1]);
}
else if(flag == 2) {
op[0] = ‘*‘;
num[0] = rand() % MAXNUM;
num[1] = rand() % MAXNUM;
ans = num[0] * num[1];
printf("%d * %d = ? \n", num[0], num[1]);
}
else {
op[0] = ‘/‘;
ans = rand() % MAXNUM;
num[1] = rand() % MAXNUM;
num[0] = ans * num[1];
printf("%d / %d = ? \n", num[0], num[1]);
}
}
int main() {
int input;
char yes_no;
while(1) {
create();
scanf("%d", &input);
if(input == ans) printf("正确\n");
else printf("错误\n");
getchar();
printf("是否继续,如果是请输入y");
scanf("%c", &yes_no);
if(yes_no != ‘y‘) break;
}
}