代码如下(C++代码),命名为随机口算挑战.cpp。
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
cout<<"挑战前友情提示:里面的除法只用写商,不用写余数;“/”表示除以,“*”表示乘,“%”表示取余,求%前面的数除以%后面的数的余数。"<<endl<<endl;
string name;
cout<<""<<endl;
cout<<"* *"<<endl;
cout<<"* 随机口算挑战 *"<<endl;
cout<<"* *"<<endl;
cout<<""<<endl;
cout<<endl;
cout<<"请输入挑战者的姓名:";
cin>>name;
cout<<endl;
cout<<"请 "<<name<<" 选手准备好挑战!!!"<<endl;
cout<<endl;
cout<<"系统正在生成试题";
for(int i=1;i<=6;i++){
cout<<".";
Sleep(520);
}
cout<<endl<<endl;
int a,b,c,d,e,n=0,s,t;
srand(time(0));
for(int i=1;i<=10;i++){
cout<<"第 "<<i<<" 题:";
a=rand()%100+1;
b=rand()%100+1;
d=rand()%5+1;
if(d==1){
c=a+b;
cout<<a<<" + "<<b<<" =";
}else if(d==2){
if(a<b){
t=a;
a=b;
b=t;
}
c=a-b;
cout<<a<<" - "<<b<<" =";
}else if(d==3){
c=a*b;
cout<<a<<" * "<<b<<" =";
}else if(d==4){
if(a<b){
t=a;
a=b;
b=t;
}
c=a/b;
cout<<a<<" / "<<b<<" =";
}else if(d==5){
if(a<b){
t=a;
a=b;
b=t;
}
c=a%b;
cout<<a<<" % "<<b<<" =";
}
cin>>e;
if(c==e){
n++;
}
s=rand()%250+1;
Sleep(s);
}
cout<<name<<" 选手得了 "<<n*10<<"分!";
return 0;
}
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/cjjbc/31314.html