#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
int AddTest(int a, int b);
void Print(int flag, int chance);
int GiveScore(int a,int b);
int main()
{
int a,b,totalScore = 0,errorCount = 0,gs;
srand(1);
int i;
for(i=1;i<=10;i++)
{
a=rand()%10+1;
b=rand()%10+1;
printf("%d:%d+%d=",i,a,b);
gs=GiveScore(a,b);
totalScore=totalScore+gs;
if(gs==0)
{
errorCount++;
}
}
printf("score = %d, error numbers = %d\n", totalScore, errorCount);
return 0;
}
int AddTest(int a, int b)
{
int s;
scanf("%d",&s);
if(s==a+b)
{
return 1;
}
else
{
return 0;
}
}
void Print(int flag, int chance)
{
if (flag == TRUE)
printf("\nRight!\n");
else if (chance < 3)
printf("\nNot correct. Try again!\n");
else
printf("\nNot correct. You have tried three times! Over!\n");
}
int GiveScore(int a,int b)
{
int chance,score=0,flag;
for(chance=1;chance<=3;chance++)
{
flag=AddTest(a,b);
Print(flag,chance);
if(flag)
{
score=10-chance+1;
break;
}
else
{
if(chance<3)
{
printf("%d+%d=",a,b);
}
}
}
return score;
}