好了 ,麻烦大家指导下
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
double addition ();
double subtract ();
double multiplication ();
double division ();
double main()
{
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;
char x;
cin>>x;
if (x=='1')
{
cout<<"您选择了加法练习: "<<endl;
addition ( );
}
if (x=='2')
{
cout<<"您选择了减法练习:"<<endl;
subtract ();
}
if (x=='3')
{
cout<<"您选择了乘法练习: "<<endl;
multiplication ();
}
if (x=='4')
{
cout<<"您选择了除法练习:"<<endl;
division ();
}
if (x=='0')
{
exit (1);
}
else
{
cout<<"请选择 (0--4)"<<endl;
return main();
}
}
double addition ()
{
double a,b,c,s;
srand (time(NULL));
a=rand ()%100;
b=rand ()%100;
cout<<a<<"+"<<b<<"="<<endl;
s=a+b;
cout<<"请输入计算结果:"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,你真聪明!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return addition ();
}
else cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,继续保持!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return addition ();
}
else cout<<"不正确,不要着急,要把握住最后一次机会喔"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,加油!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return addition ();
}
else cout<<"不正确,要加强练习喔!正确的答案为:"<<s<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return addition ();
}
double subtract ()
{
double a,b,c,s;
srand (time(NULL));
a=rand ()%100;
b=rand ()%100;
cout<<a<<"-"<<b<<"="<<endl;
s=a-b;
cout<<"请输入计算结果:"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,你真聪明!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return subtract ();
}
else cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,继续保持!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return subtract ();
}
else cout<<"不正确,不要着急,要把握住最后一次机会喔"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,加油!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return subtract ();
}
else cout<<"不正确,要加强练习喔!正确的答案为:"<<s<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return subtract ();
}
double multiplication ()
{
double a,b,c,s;
srand (time(NULL));
a=rand ()%100;
b=rand ()%100;
cout<<a<<"*"<<b<<"="<<endl;
s=a*b;
cout<<"请输入计算结果:"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,你真聪明!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return multiplication ();
}
else cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,继续保持!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return multiplication ();
}
else cout<<"不正确,不要着急,要把握住最后一次机会喔"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,加油!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return multiplication ();
}
else cout<<"不正确,要加强练习喔!正确的答案为:"<<s<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return multiplication ();
}
double division ()
{
double a,b,c,s;
cout<<"你选择了除法练习(结果四舍五入,保留两位小数)"<<endl;
do
{
srand (time(NULL));
a=rand ()%100;
b=rand ()%100;
}
while (b==0);
cout<<a<<"/"<<b<<"="<<endl;
s=a/b;
cout<<"请输入计算结果:"<<endl;
s=int(s*100.0+0.5)/100.00;
cin>>c;
if (s==c)
{
cout<<"正确,你真聪明!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return division ();
}
else cout<<"不正确,再想一想,你还有两次机会!"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,继续保持!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return division ();
}
else cout<<"不正确,不要着急,要把握住最后一次机会喔"<<endl;
cin>>c;
if (s==c)
{
cout<<"正确,加油!"<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return division ();
}
else cout<<"不正确,要加强练习喔!正确的答案为:"<<s<<endl;
cout<<"是否要继续练习? (Y/N)"<<endl;
char z;
cin>>z;
if (z=='n'||z=='N')
{
return main ();
}
else
return division ();
}
长是长了点
但水平有限
有地方什么能改进的
有什么要提问的
有什么地方有错的
请大家多多指导啊
谢谢大家的 支持
努力
努力……