#include
#include
#include
#include
void eval1(int );//对正确答案的评价
void eval2(int );//对错误答案的评价
int main()
{
int a,b;
int answer1, answer2;//记录+、-、*的答案
float answer3, answer4;//记录/的答案
int flags = 1;
int select, evaluate;
int count1 = 0, count2 = 0;//记录总题数、及正确答案的题目数
int temp;
int scores = 0;//记录分数
float rate;//记录正确率
srand((unsigned)time(NULL));
while(flags)
{
count1++;
a = rand() % 10 + 1;
b = rand() % 10 + 1;
evaluate = rand() % 4 + 1;
select = rand() % 4 + 1;
//加法运算
if(select == 1)
{
answer1 = a + b;
printf("%d + %d = ?\n",a,b);
printf("Please input the answer:");
scanf("%d",&answer2);
if(answer1 == answer2)
{
count2++;
scores += 10;
printf("Right\n");
}
else
{
printf("Wrong\n");
}
}
//减法运算
else if(select == 2)
{
if(b > a)
{
temp = a;
a = b;
b = temp;
}
answer1 = a - b;
printf("%d - %d = ?\n",a,b);
printf("Please input the answer:");
scanf("%d",&answer2);
if(answer1 == answer2)
{
printf("Right\n");
count2++;
scores += 10;
}
else
{
printf("Wrong\n");
}
}
//乘法运算
else if(select == 3)
{
answer1 = a * b;
printf("%d * %d = ?\n",a,b);
printf("Please input the answer:");
scanf("%d",&answer2);
if(answer1 == answer2)
{
printf("Right\n");
count2++;
scores +=10;
}
else
{
printf("Wrong\n");
}
}
//除法运算
else
{
//保证分母不为0
if( b == 0)
b++;
answer3 = (float)a / b;
printf("%d / %d = ?\n",a,b);
printf("Please input the answer:");
scanf("%f",&answer4);
if(fabs(answer3 - answer4) < 0.001)
{
printf("Right\n");
count2++;
scores += 10;
}
else
{
printf("Wrong\n");
}
}
//判断正确率
if(count1 == 10)
{
rate = (float)count2 / count1;
if( rate > 0.75)
{
flags = 0;
printf("Scores: %d Rate: %%%.0f\n",scores,rate*100);
eval1(evaluate);
}
else
{
printf("Scores: %d Rate: %%%.0f\n",scores,rate*100);
printf("Please make the rate greater than %75\n");
eval2(evaluate);
}
}
}
return 0;
}
void eval1(int a)
{
switch(a)
{
case 1:printf("Very good!\n");break;
case 2:printf("Excellent!\n");break;
case 3:printf("Nice work!\n");break;
default:printf("Keep up the good work!\n");break;
}
}
void eval2(int a)
{
switch(a)
{
case 1:printf("No. Please try again.\n");break;
case 2:printf("Wrong. Try once more.\n");break;
case 3:printf("Don’t give up!\n");break;
default:printf("Not correct. Keep trying.\n");break;
}
}
大概做了下任务6,其它的自己实践一下吧
易语言吧!10天包会出程序!
c语言吗?还是vb还是perl~
其实这是个锻炼自己的机会
哪里不会的,赶紧问
晚上有课,七点前,十点后才能答复