小学生四则运算
#include<stdio.h>
#include<math.h>
#include<time.h>
int main()
{
int i = 1;
int flag = 0;
float rate = 0;
char good[4][40] = { "Very good!","Excellent!","Nice work!","Keep up the good work!" };
char wrong[4][40] = { "No.Please try again.","Wrong.Try once more.","Don’t give up!","Not correct.Keep trying." };
while(rate<0.75)
{
int i = 1;
while (i<=10)
{
srand(time(0));
int ra3 = rand() % 4 + 0;
int ra1 = rand() % 10 + 1;
int ra2 = rand() % 10 + 1;
int ra4 = rand() % 4 + 0;
float a;
char ch[4] = { '+','-','*','/' };
printf(" %d%c% d=", ra1, ch[ra3], ra2);
scanf("%f", &a);
switch (ra3)
{
case 0:
if (a == ra1 + ra2)
{
printf(" % s\n", good[ra4]);
flag++;
i++;
break;
}
else
{
printf("%s\n", wrong[ra4]);
i++;
break;
}
case 1:
if (a == ra1 - ra2)
{
printf("%s\n", good[ra4]);
flag++;
i++;
break;
}
else
{
printf("%s\n", wrong[ra4]);
i++;
break;
}
case 2:
if (a == ra1 * ra2)
{
printf("%s\n", good[ra4]);
flag++;
i++;
break;
}
else
{
printf("%s\n", wrong[ra4]);
i++;
break;
}
case 3:
if (a == (float)ra1 / ra2)
{
printf("%s\n", good[ra4]);
flag++;
i++;
break;
}
else
{
printf("%s\n", wrong[ra4]);
i++;
break;
}
}
}
rate = flag / 10.0;
printf("%f\n", rate);
if (rate < 0.75)
printf("again\n");
}
return 0;
}