#include "iostream"
#include "cstdlib"
#include "ctime"
using namespace std;
int main()
{
srand(time(NULL));
int i;
int t=0;
for(i=0;i<10;i++)
{ double c,d;
int a=rand()%100;
int b=rand()%100;
int symbol=rand()%4;
if(symbol==0)
{ cout<<a<<"+"<<b<<"=";
c=a+b;
cin>>d;
if(d==c)
{
cout<<"答案正确"<<endl;
t++;
}
if(d!=c)
{
cout<<"答案错误"<<endl;
}
}
if(symbol==1)
{ cout<<a<<"-"<<b<<"=";
c=a-b;
cin>>d;
if(d==c)
{
cout<<"答案正确"<<endl;
t++;
}
if(d!=c)
{
cout<<"答案错误"<<endl;
}
}
if(symbol==2)
{
cout<<a<<"*"<<b<<"=";
c=a*b;
cin>>d;
if(d==c)
{
cout<<"答案正确"<<endl;
t++;
}
if(d!=c)
{
cout<<"答案错误"<<endl;
}
}
if(symbol==3)
{
cout<<a<<"/"<<b<<"=";
c=a/b;
cin>>d;
if(d==c)
{
cout<<"答案正确"<<endl;
t++;
}
if(d!=c)
{
cout<<"答案错误"<<endl;
}
}
}
cout<<"共计做对了"<<t<<"道题";
return 0;
}
运行结果:
知识点总结:随机数函数应用
学习心得:这个题目编的还是有漏洞,需要进一步完善