自编小程序,还有一些困惑,不太稳定,欢迎私信或评论,提供建议、bug和不足之处。
代码:
#include<bits/stdc++.h>
#include <windows.h>
#include <ctime>
using namespace std;
void clean();
string nandu();
void xunhuan();
void shuju();
long long a,b,c,cishu,xuanze,cf_a,cf_b,jf_a,jf_b,jj_a,jj_b,jj_d,chuf_a,chuf_b,cc_a,cc_b,cc_d,jjcc_a,jjcc_b,jjcc_c,jjcc_d,jjcc_e,xiangzi_a,xiangzi_b,xiangzi_c,xiangzi_d,xiangzi_e,duqu_a,yaoshi;
long long score;
double score_pj;
int main(){
system("color F1");
while(1){
cout<<"禁止输入文字!!!\n若暂停,输入大于等于100000的数(注:除法计算保留整数)"<<endl;
cout<<"请选择1.加法 2.减法 3.加减混合 4.乘法 5.除法 6.乘除混合 7.加减乘除混合 8.退出"<<endl;
cin>>xuanze;
yaoshi=5;
if (xuanze==1)
{
while(yaoshi>0){
yaoshi++;
cishu++;
shuju();
srand(time(0));
xiangzi_a=a=rand()%100;
xiangzi_b=b=rand()%100;
nandu();
cout<<"难度:"<<nandu()<<endl;
cout<<a<<"+"<<b<<"=";
cin>>c;
if(c>=100000){
yaoshi=0;
Sleep(1100);system("cls");
}
if(c!=a+b){
cout<<"错误!\n"<<"正确答案为:"<<a+b<<endl;
Sleep(1100);system("cls");
}
else{
cout<<"正确"<<endl;
score++;
Sleep(1100);system("cls");
}
}
}
if (xuanze==2){
yaoshi++; //减
while(yaoshi>0){
cishu++;
srand(time(0));
xiangzi_a=jf_a=rand()%100;
xiangzi_b=jf_b=rand()%100;
shuju();
cout<<"难度:"<<nandu()<<endl;
cout<<jf_a<<"-"<<jf_b<<"=";
cin>>c;
if(c>=100000){
//cishu=0;
yaoshi=0;
Sleep(1100);system("cls");
}
if(c!=jf_a-jf_b){
cout<<"错误!\n"<<"正确答案为:"<<jf_a-jf_b<<endl;
cout<<"分数:"<<score<<endl<<endl;
Sleep(1100);system("cls");
}
else{
cout<<"正确"<<endl;
score++;
//cout<<"分数:"<<score<<endl<<endl;
Sleep(1100);system("cls");
}
}
//break;
}
if (xuanze==3){
while(yaoshi>0){
cishu++;
srand(time(0));
xiangzi_a=jj_a=rand()%100;
xiangzi_b=jj_b=rand()%100;
xiangzi_c=jj_d=rand()%100;
shuju();
//cout<<"次数:"<<cishu<<endl;
cout<<jj_a<<"-"<<jj_b<<"+"<<jj_d<<"=";
cin>>c;
if(c>=100000){//
//cishu=0;
yaoshi=0;
clean();
break;
}
if(c!=jj_a-jj_b+jj_d){//
cout<<"错误!\n"<<"正确答案为:"<<jj_a-jj_b+jj_d<<endl;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
else{//
cout<<"正确"<<endl;
score++;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
}
//break;
}
if (xuanze==4){
while(yaoshi>0){
cishu++;
srand(time(0));
xiangzi_a=cf_a=rand()%100;
xiangzi_b=cf_b=rand()%100;
shuju();
//cout<<"次数:"<<cishu<<endl;
cout<<cf_a<<"*"<<cf_b<<"=";
cin>>c;
if(c>=100000){
//cishu=0;
yaoshi=0;
clean();
break;
}
if(c!=cf_a*cf_b){
cout<<"错误!\n"<<"正确答案为:"<<cf_a*cf_b<<endl;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
else{
cout<<"正确"<<endl;
score++;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
}
// break;
}
if (xuanze==5){
while(yaoshi>0){
cishu++;
srand(time(0));
xiangzi_a=chuf_a=rand()%100;
xiangzi_b=chuf_b=rand()%100;
shuju();
//cout<<"次数:"<<cishu<<endl;
cout<<chuf_a<<"/"<<chuf_b<<"=";
cin>>c;
if(c>=100000){
//cishu=0;
yaoshi=0;
clean();
// break;
}
if(c!=chuf_a/chuf_b){
cout<<"错误!\n"<<"正确答案为:"<<chuf_a/chuf_b<<endl;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
else{
cout<<"正确"<<endl;
score++;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
}
// break;
}
if (xuanze==6){
while(yaoshi>0){
cishu++;
srand(time(0));
xiangzi_a=cc_a=rand()%100;
xiangzi_b=cc_b=rand()%100;
xiangzi_c=cc_d=rand()%100;
//cout<<"次数:"<<cishu<<endl;
shuju();
cout<<cc_a<<"*"<<cc_b<<"/"<<cc_d<<"=";
cin>>c;
if(c>=100000){
//cishu=0;
yaoshi=0;
clean();
// break;
}
if(c!=cc_a*cc_b/cc_d){
cout<<"错误!\n"<<"正确答案为:"<<cc_a*cc_b/cc_d<<endl;
//cout<<"分数:"<<score<<endl<<endl;
clean();
}
else{
cout<<"正确"<<endl;
score++;
clean();
}
}
}
if (xuanze==7){
while(yaoshi>0){
int sj_a;
cishu++;
srand(time(0));
xiangzi_a=jjcc_a=rand()%100;
xiangzi_b=jjcc_b=rand()%100;
xiangzi_c=jjcc_c=rand()%100;
xiangzi_d=jjcc_d=rand()%100;
xiangzi_e=jjcc_e=rand()%100;
sj_a=rand()%12;
if(sj_a==1){
cout<<jjcc_a<<"+"<<jjcc_b<<"-"<<jjcc_c<<"*"<<jjcc_d<<"/"<<jjcc_e<<"=";
cin>>c;
if(c>=100000){
yaoshi=0;
clean();
}
if(c!=jjcc_a+jjcc_b-jjcc_c*jjcc_d/jjcc_e){
cout<<"错误!\n"<<"正确答案为:"<<jjcc_a+jjcc_b-jjcc_c*jjcc_d/jjcc_e<<endl;
clean();
}
else{
cout<<"正确"<<endl;
score++;
clean();
}
}
if(sj_a==2){
cout<<jjcc_a<<"-"<<jjcc_b<<"+"<<jjcc_c<<"*"<<jjcc_d<<"/"<<jjcc_e<<"=";
cin>>c;
if(c>=100000){
yaoshi=0;
clean();
}
if(c!=jjcc_a-jjcc_b+jjcc_c*jjcc_d/jjcc_e){
cout<<"错误!\n"<<"正确答案为:"<<jjcc_a-jjcc_b+jjcc_c*jjcc_d/jjcc_e<<endl;
clean();
}
else{
cout<<"正确"<<endl;
score++;
clean();
}
}
}
}
if(xuanze==8){
break;
}
}
return 0;
}
void clean(){
Sleep(1100);
system("cls");
}
string nandu(){
string nandu;
if((xiangzi_a==a)&&(xiangzi_b==b)){
nandu="简单";
}
return nandu;
}
void shuju(){
cout<<setw(110)<<right<<"分数:"<<score<<endl<<setw(110)<<right<<"次数:"<<cishu<<endl; //<<setw(110)<<right<<"平均分:"<<score_pj<<endl
}
只有服从大自然,才能战胜大自然。 6gn.