作者在 2008-07-03 19:23:07 发布以下内容
#include<iostream>
#include <time.h>
#include<stdlib.h>
using namespace std;
void addition();
void subtract();
void multiplication();
void division();
int main()
{
while(true)
{
char i;
cout<<" *************************************** "<<endl;
cout<<endl;
cout<<" 小学生四则运算练习系统 "<<endl;
cout<<endl;
cout<<" *************************************** "<<endl;
cout<<endl;
cout<<" 1--加法练习 "<<endl;
cout<<" 2--减法练习 "<<endl;
cout<<" 3--乘法练习 "<<endl;
cout<<" 4--除法练习 "<<endl;
cout<<" 0--退出 "<<endl;
cout<<"请选择(0~4): "<<endl;
cin>>i;
switch(i)
{
case '1':
cout<<"您选择了加法练习: "<<endl;
addition();
break;
case '2':
cout<<"您选择了减法练习: "<<endl;
subtract();
break;
case '3':
cout<<"您选择了乘法练习: "<<endl;
multiplication();
break;
case '4':
cout<<"您选择了除法练习(结果保留两位小数):"<<endl;
division();
break;
case '0':
exit(1);
}
}
return ;
}
void addition()
{
int a,b,c,d;
char s,y[10];
do{
srand(time(NULL));
a=rand()%100+1;
b=rand()%100+1;
c=a+b;
cout<<a<<"+"<<b<<"="<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return;
}
while(s!='n'||s!='N');
}
void subtract()
{
int a,b,c,d;
char s,y[10];
do{
srand(time(NULL));
a=rand()%100+1;
b=rand()%100+1;
/*if(a<b)
{
double t;
t=a;
a=b;
b=t;
}*/
c=a-b;
cout<<a<<"-"<<b<<"="<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return;
}
while(s!='n'||s!='N');
}
void multiplication()
{
int a,b,c,d;
char s,y[10];
do{
srand(time(NULL));
a=rand()%100+1;
b=rand()%100+1;
c=a*b;
cout<<a<<"*"<<b<<"="<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return ;
}
while(s!='n'||s!='N');
}
void division()
{
double a,b,c,d;
char s,y[10];
do{
do
{
srand(time(NULL));
a=rand()%100+0;
b=rand()%100+1;
c=a/b;
}while(b==0);
cout<<a<<"/"<<b<<"="<<endl;
cin>>y;
d=atof(y);
c=int (c*100.0+0.5)/100.0;
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atof(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atof(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return;
}
while(s!='n'||s!='N');
}
#include <time.h>
#include<stdlib.h>
using namespace std;
void addition();
void subtract();
void multiplication();
void division();
int main()
{
while(true)
{
char i;
cout<<" *************************************** "<<endl;
cout<<endl;
cout<<" 小学生四则运算练习系统 "<<endl;
cout<<endl;
cout<<" *************************************** "<<endl;
cout<<endl;
cout<<" 1--加法练习 "<<endl;
cout<<" 2--减法练习 "<<endl;
cout<<" 3--乘法练习 "<<endl;
cout<<" 4--除法练习 "<<endl;
cout<<" 0--退出 "<<endl;
cout<<"请选择(0~4): "<<endl;
cin>>i;
switch(i)
{
case '1':
cout<<"您选择了加法练习: "<<endl;
addition();
break;
case '2':
cout<<"您选择了减法练习: "<<endl;
subtract();
break;
case '3':
cout<<"您选择了乘法练习: "<<endl;
multiplication();
break;
case '4':
cout<<"您选择了除法练习(结果保留两位小数):"<<endl;
division();
break;
case '0':
exit(1);
}
}
return ;
}
void addition()
{
int a,b,c,d;
char s,y[10];
do{
srand(time(NULL));
a=rand()%100+1;
b=rand()%100+1;
c=a+b;
cout<<a<<"+"<<b<<"="<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return;
}
while(s!='n'||s!='N');
}
void subtract()
{
int a,b,c,d;
char s,y[10];
do{
srand(time(NULL));
a=rand()%100+1;
b=rand()%100+1;
/*if(a<b)
{
double t;
t=a;
a=b;
b=t;
}*/
c=a-b;
cout<<a<<"-"<<b<<"="<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return;
}
while(s!='n'||s!='N');
}
void multiplication()
{
int a,b,c,d;
char s,y[10];
do{
srand(time(NULL));
a=rand()%100+1;
b=rand()%100+1;
c=a*b;
cout<<a<<"*"<<b<<"="<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atoi(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return ;
}
while(s!='n'||s!='N');
}
void division()
{
double a,b,c,d;
char s,y[10];
do{
do
{
srand(time(NULL));
a=rand()%100+0;
b=rand()%100+1;
c=a/b;
}while(b==0);
cout<<a<<"/"<<b<<"="<<endl;
cin>>y;
d=atof(y);
c=int (c*100.0+0.5)/100.0;
if(d==c)
{
cout<<"正确,你真聪明!";
}
else
if(d!=c)
{
cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>y;
d=atof(y);
if(d==c)
{
cout<<"正确,继续保持!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,不要着急,要把握住最后一次机会!"<<endl;
cin>>y;
d=atof(y);
if(d==c)
{
cout<<"正确,加油!"<<endl;
}
else
if(d!=c)
{
cout<<"不正确,要加强练习喔!"<<endl;
cout<<"正确答案:"<<c<<endl;
}
}
}
cout<<"是否继续练习(是y/n否)"<<endl;
cin>>s;
if(s=='n'||s=='N')
return;
}
while(s!='n'||s!='N');
}