问题遇到的现象和发生背景
某小学要进行口算比赛,针对不同年级要出不同类型的题目,现要求编写2个程序,一个是完成题目的随机生成(teacher的工作),另一个是你来参加这个比赛(学生的工作)。
功能:
(1)题目难度分类(只考虑3个难度,题目只考虑2个操作数的情况,要求操作数和结果都不为负数)
1)文件名为easy.txt,两个操作数为10以内的加减法,减法操作时结果不能为负数;
2)文件名为medium.txt,操作数、结果皆为[0, 100]以内的加减乘除四则运算,除数操作时除数不能为0;
3)文件名为difficult.txt,分子分母均小于10的分数的加减乘除四则运算,要求操作数和结果均为不可约的情况,即2/6应该花简称1/3,6/3应化简成2。对于假分数不用化简成带分数形式。
问题相关代码,请勿粘贴截图
运行结果及报错内容
VS2019显示"fopen_s"用于调用的参数太少C2198
我的解答思路和尝试过的方法
我想要达到的结果
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
char n3[5];
char n7[5];
char n8[10];
void easy(int j)
{
int a, n1, n2;
int n4;
char b;
srand((unsigned int)time(0));
for (size_t i = 0; i < 2; i++)
{
a = rand();
int p = a % (10 - 0 + 1) + 1;
if (i == 0)
n1 = p;
else
n2 = p;
sleep(1500);
}
srand((unsigned int)time(0));
n4 = rand();
if (n4 % 2 == 1)
b = '+';
else
b = '-';
n3[1] = n1; n3[2] = b; n3[3] = n2; n3[4] = '=';
}
void medium(int j)
{
int a, n1, n2;
int n4;
char b;
int t;
srand((unsigned int)time(0));
for (size_t i = 0; i < 2; i++)
{
a = rand();
int p = a % (100 - 0 + 1) + 1;
if (i == 0)
n1 = p;
else
n2 = p;
sleep(1500);
}
srand((unsigned int)time(0));
n4 = rand();
t = n4 % 4;
if (t == 1)
b = '+';
else if (t == 2)
b = '-';
else if (t == 3)
b = '*';
else
b = '/';
if (b == '/' && n7[3] == 0)
n7[3]++;
n7[1] = n1; n7[2] = b; n7[3] = n2; n7[4] = '=';
}
void diffucult(int j)
{
int a, n1, n2;
int n4;
char b;
int n10, n11;
int t;
srand((unsigned int)time(0));
for (size_t i = 0; i < 4; i++)
{
a = rand();
int p = a % (10 - 0 + 1) + 1;
if (i == 0)
n1 = p;
else if (i == 1)
n2 = p;
else if (i == 2)
n10 = p;
else if (i == 3)
n11 == p;
sleep(1500);
}
srand((unsigned int)time(0));
n4 = rand();
t = n4 % 4;
if (t == 1)
b = '+';
else if (t == 2)
b = '-';
else if (t == 3)
b = '*';
else
b = '/';
if (b == '/' && n7[3] == 0)
n7[3]++;
n8[0] == n1; n8[2] == '/'; n8[3] == n2; n8[4] == 'b';
n8[5] == n3; n8[6] == '/'; n8[7] == n4; n8[9] == '=';
}
int main()
{
int a, b;
int j;
int n1, n2;
FILE* fp;
if ((fp = fopen_s("easy.text", "w")) == NULL)
{
printf("打开失败");
exit(-1);
}
for (j = 0; j < 20; j++)
{
easy(j);
fprintf(fp,"%s",n3);
}
fclose(fp);
if ((fp = fopen_s("medium.text", "w")) == NULL)
{
printf("打开失败");
exit(-1);
}
for (j = 0; j < 20; j++)
{
medium(j);
fprintf(fp, "%s", n7);
}
fclose(fp);
for (j = 0; j < 20; j++)
{
easy(j);
fprintf(fp,"%s",n3);
}
fclose(fp);
if ((fp = fopen_s("difficult.text", "w")) == NULL)
{
printf("打开失败");
exit(-1);
}
for (j = 0; j < 20; j++)
{
difficult(j);
fprintf(fp, "%s", n8);
}
fclose(fp);
}