#include<iostream>
#include<cstdio>
#include<time.h>
#include<cstdlib>
using namespace std
;
int judge(int a
,int b
,int c
)
{
if(a
+b
==c
) return 1;
else return 0;
}
void adt(int a
,int b
)
{
printf("%d+%d=",a
,b
);
}
int main()
{
int i
,a
,b
,c
,chance
,score
=0;
srand(unsigned(time(NULL)));
for(i
=1;i
<=10;i
++)
{
a
=rand()%10+1;
b
=rand()%10+1;
chance
=3;
while(chance
--)
{
adt(a
,b
);
cin
>>c
;
if(judge(a
,b
,c
))
{
cout
<<"Right"<<endl
;
score
++;
break;
}
else
if(chance
>0)
cout
<<"Try again!"<<chance
<<"chances left!"<<endl
;
else
cout
<<"Sorry! No chance left! Try a new test!"<<endl
;
}
}
cout
<<"Congratulations! You got "<<score
<<" scores!"<<endl
;
system("pause");
return 0;
}
转载请注明原文地址: https://mac.8miu.com/read-498577.html