如果你说的是在题目回答完之后加入continue或者break选项的话
那么可以尝试在循环后面加入
我这里用c++重新写一遍。[C++] 纯文本查看 复制代码 #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
printf("***************************************************************************\n");
printf("*******************************小学生测试******************************* \n");
printf("***************************************************************************\n");
int magic1,magic2;
int sum,summ;
int c;
char a;
int counter;
int t;
int i,j=0,k=0,l=5;
string AN;
for(i=0; i<5; i++)
{
srand((unsigned )time(NULL));
do
{
magic1 = rand() % 50+1;
magic2 = rand() % 50+1;
}
while(magic1+magic2>=50);
c = rand() % 2;
counter=0;
do
{
if(c==0)
{
a ='+';
sum = magic1 + magic2;
}
if(c==1)
{
a = '-';
if(magic1<magic2)
{
t = magic1;
magic1 = magic2;
magic2 = t;
}
sum = magic1 - magic2;
}
printf("Question:%d%c%d\n",magic1,a,magic2);
printf("Please enter your answer:\n");
scanf("%d",&summ);
if(summ == sum)
{
printf("Right!\n");
break;
}
else
{
printf("Wrong!请重新输入。\n");
if(counter<1)
{
k++;
}
}
counter++;
}
while(counter < 3);
printf("The right answer is:%d\n",sum);
printf("Wanna continue?(Yes or NO)");
cin >> AN;
if(AN == "yes")
{
continue;
}
else
{
break;
}
}
j=l-k;
FILE*fp;
fp = fopen("data.txt","w");
fprintf(fp,"正确个数:%d\n错误个数:%d\n",j,k);
printf("正确个数:%d\n错误个数:%d\n",j,k);
return 0;
}
不过你这个原来写的就有BUG;建议你重新用C++调用c语言的函数库来写一遍
这个运行的话
可以尝试用COUT或者cin
不需要用scanf&printf 这个格式化输入输出 |