1 Star 0 Fork 0

吴宇辰 / learngit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
szys.txt 3.63 KB
一键复制 编辑 原始数据 按行查看 历史
吴宇辰 提交于 2020-02-26 08:42 . wrote a szys file
#include<iostream>
#include<cstdlib>
#include<math.h>
#include<stdio.h>
#include<ctime>
using namespace std;
int r=0;
int w=0;
void add() { //加法运算
srand(time(0));
int a,b,c,d;
a=rand()%100;
b=rand()%100;
c=rand()%100;
cout<<"请回答:"<<a<< "+"<<b<< "+"<<c<< "= ";
cin>>d;
if(a+b+c==d) {
cout<<"回答正确!";
r++;
} else {
cout<<"回答错误!";
w++;
}
}
void minus() { //减法运算
srand(time(0));
int a,b,c,d;
a=rand()%100;
b=rand()%100;
c=rand()%100;
cout<<"请回答:"<<a<< "-"<<b<< "-"<<c<< "= ";
cin>>d;
if(a-b-c==d) {
cout<<"回答正确!";
r++;
} else {
cout<<"回答错误!";
w++;
}
}
void multiply() { //乘法运算
srand(time(0));
int a,b,c,d;
a=rand()%100;
b=rand()%100;
c=rand()%100;
cout<<"请回答:"<<a<< "*"<<b<< "*"<<c<< "= ";
cin>>d;
if(a*b*c==d) {
cout<<"回答正确!";
r++;
} else {
cout<<"回答错误!";
w++;
}
}
void divide() { //除法运算
srand(time(0));
int a,b,c,d;
a=rand()%100;
b=rand()%100;
c=rand()%100;
cout<<"请回答:"<<a<< "/"<<b<< "/"<<c<< "= ";
cin>>d;
if(a/b/c==d) {
cout<<"回答正确!";
r++;
} else {
cout<<"回答错误!";
w++;
}
}
void main() {
int choise;
int con=0;
int i=0,j=0;
cout<<"欢迎进入简易四则运算";
while(1) {
cout<<"请选择:";
cout<<" 加法运算(请输入1)";
cout<<" 减法运算(请输入2)";
cout<<" 乘法运算(请输入3)";
cout<<" 除法运算(请输入4)";
cout<<" 退出运算(请输入5)";
if(con==0)
cin>>choise;
switch(choise) {
case 1://加法
cout<<"请输入题目数目:";
cin>>i;
if(i>0) {
for(j=0; j<i; j++) {
add();
}
} else
cout<<"输入错误,请重新输入!";
break;
case 2://减法
cout<<"请输入题目数目:";
cin>>i;
if(i>0) {
for(j=0; j<i; j++) {
minus();
}
} else
cout<<"输入错误,请重新输入!";
break;
case 3://乘法
cout<<"请输入题目数目:";
cin>>i;
if(i>0) {
for(j=0; j<i; j++) {
multiply();
}
} else
cout<<"输入错误,请重新输入!";
break;
case 4://除法
cout<<"请输入题目数目:";
cin>>i;
if(i>0) {
for(j=0; j<i; j++) {
divide();
}
} else
printf("输入错误,请重新输入!");
break;
case 5:
return;
}
cout<<"继续运算?(请输入1)";
cout<<"重新选择?";
cout<<"退出运算?(请输入3)";
cin>>con;
if(con==1)
con=1;
else if(con==2)
con=0;
else if(con==3)
break;
else
cout<<"抱歉!,你输入的指令有误!请重新输入!";
}
cout<<"您总共完成了"<<r+w<<"道题 正确"<<r<<"道 错误"<<w<<"道";
system("pause");
}
1
https://gitee.com/wu_yu_chen1/learngit.git
git@gitee.com:wu_yu_chen1/learngit.git
wu_yu_chen1
learngit
learngit
master

搜索帮助