随机生成计算题,可以帮助需要提升计算能力的朋友。代码里有便民文字,我就不多介绍了。
#include<bits/stdc++.h> using namespace std; int main() { long long n,a,x,z,s,s1,l,y,a1,m123,yushu; double t=0; srand(time(0)); cout<<"你总共要做几题。如5 就是做5题"<<endl; cin>>n; cout<<"你的题在什么范围内。如1 100,就是1到100之间"<<endl; cin>>s>>s1; cout<<"你要做什么题,1是加,2是没有负数的减法,3是乘,4是有负数的减法,5是没有余数的除法,6是有余数的除法"<<endl; cin>>l; if(l==1) { for(int i=1;i<=n;i++) { x=rand()%s1+s; y=rand()%s1+s; cout<<x<<"+"<<y<<"="; cin>>a; if(a==x+y) { cout<<"正确"<<endl; cout<<endl; cout<<endl; t++; } if(a!=x+y) { cout<<"错误"<<endl; cout<<"正确答案是:"<<x+y<<endl; cout<<endl; cout<<endl; } } } if(l==2) { for(int i=1;i<=n;i++) { x=rand()%s1+s; y=rand()%s1+s; if(x>=y) cout<<x<<"-"<<y<<"="; else { m123=x; x=y; y=m123; cout<<x<<"-"<<y<<"="; } cin>>a; if(a==x-y) { cout<<"正确"<<endl; cout<<endl; cout<<endl; t++; } if(a!=x-y) { cout<<"错误"<<endl; cout<<"正确答案是:"<<x-y<<endl; cout<<endl; cout<<endl; } } } if(l==3) { for(int i=1;i<=n;i++) { x=rand()%s1+s; y=rand()%s1+s; cout<<x<<"*"<<y<<"="; cin>>a; if(a==x*y) { cout<<"正确"<<endl; cout<<endl; cout<<endl; t++; } if(a!=x*y) { cout<<"错误"<<endl; cout<<"正确答案是:"<<x*y<<endl; cout<<endl; cout<<endl; } } } if(l==4) { for(int i=1;i<=n;i++) { x=rand()%s1+s; y=rand()%s1+s; cout<<x<<"-"<<y<<"="; cin>>a; if(a==x-y) { cout<<"正确"<<endl; cout<<endl; cout<<endl; t++; } if(a!=x-y) { cout<<"错误"<<endl; cout<<"正确答案是:"<<x-y<<endl; cout<<endl; cout<<endl; } } } if(l==5) { for(int i=1;i<=n;i++) { x=rand()%s1+s; y=rand()%s1+s; while(x<y||x%y!=0) { x=rand()%s1+s; y=rand()%s1+s; } cout<<x<<"/"<<y<<"="<<" 注:/是指除号"<<"\n"; cin>>a; if(a==x/y) { cout<<"正确"<<endl; cout<<endl; cout<<endl; t++; } if(a!=x/y) { cout<<"错误"<<endl; cout<<"正确答案是:"<<x/y<<endl; cout<<endl; cout<<endl; } } } if(l==6) { for(int i=1;i<=n;i++) { x=rand()%s1+s; y=rand()%s1+s; while(x<y) { x=rand()%s1+s; y=rand()%s1+s; } cout<<x<<"/"<<y<<"="<<" 余数= 注:/是指除号"<<"\n"; cin>>a; cin>>yushu; if(a==x/y&&yushu==x%y) { cout<<"正确"<<endl; cout<<endl; cout<<endl; t++; } if(a!=x/y||yushu!=x%y) { cout<<"错误"<<endl; cout<<"正确答案是:商:"<<x/y<<"余:"<<x%y<<endl; cout<<endl; cout<<endl; } } } a1=n; cout<<"你对了"<<t<<"题"<<endl; cout<<"你的正确率是"<<t/n*100<<"%"<<endl; return 0; }