乐极生悲
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
double addition ();
double subtract ();
double multiplication ();
double division ();
int main ()
{
char shuzi;
xuanze:
{
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<<endl;
cout<<"
0--退出
"<<endl;
cout<<"请选择(0--4):
"<<endl;
cin>>shuzi;
switch (shuzi)
{
case '1':
cout<<"你选择了加法练习"<<endl;
addition ();
if('n'||'N')
goto xuanze;
break;
case '2':
cout<<"你选择了减法练习"<<endl;
subtract ();
if('n'||'N')
goto xuanze;
break;
case '3':
cout<<"你选择了乘法练习 "<<endl;
multiplication ();
if('n'||'N')
goto xuanze;
break;
case '4':
cout<<"你选择了除法练习 "<<endl;
division ();
if('n'||'N')
goto xuanze;
break;
case '0':
cout<<"按任意键退出"<<endl;
break;
default:
{
goto xuanze;
}
}
}
return 0;
}
double addition ()
{
int n,a,b,s;
wenti:
{
time(NULL);
srand(time(NULL));
a=rand()%100;
b=rand()%100;
s=a+b;
cout<<a<<"+"<<b<<"=?"<<endl;
cin>>n;
if(n==s)
{
cout<<"正确,你真聪明!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"结果不对,你再想想,你还有两次机会!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,继续保持!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,不要着急,要把握住最后一次机会喔!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,加油!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,要加强练习喔!"<<" "<<"正确答案为:"<<s<< endl;
cout<<endl;
goto xunwen;
}
}
xunwen:
{
char ch;
cout<<"是否繼續?是Y/否N"<<endl;
cin>>ch;
if (ch=='n' || ch=='N')
{
return s;
}
else
{
if (ch=='y' || ch=='Y')
{
goto wenti;
}
else
{
goto xunwen;
}
}
}
}
}
double subtract ()
{
int n,a,b,s;
wenti:
{
time(NULL);
srand(time(NULL));
a=rand()%100;
b=rand()%100;
s=a-b;
cout<<a<<"-"<<b<<"=?"<<endl;
cin>>n;
if(n==s)
{
cout<<"正确,你真聪明!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"结果不对,你再想想,你还有两次机会!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,继续保持!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,不要着急,要把握住最后一次机会喔!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,加油!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,要加强练习喔!"<<" "<<"正确答案为:"<<s<< endl;
cout<<endl;
goto xunwen;
}
}
xunwen:
{
char ch;
cout<<"是否繼續?是Y/否N"<<endl;
cin>>ch;
if (ch=='n' || ch=='N')
{
return s;
}
else
{
if (ch=='y' || ch=='Y')
{
goto wenti;
}
else
{
goto xunwen;
}
}
}
}
}
double multiplication ()
{
int n,a,b,s;
wenti:
{
time(NULL);
srand(time(NULL));
a=rand()%100;
b=rand()%100;
s=a*b;
cout<<a<<"*"<<b<<"=?"<<endl;
cin>>n;
if(n==s)
{
cout<<"正确,你真聪明!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"结果不对,你再想想,你还有两次机会!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,继续保持!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,不要着急,要把握住最后一次机会喔!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,加油!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,要加强练习喔!"<<" "<<"正确答案为:"<<s<< endl;
cout<<endl;
goto xunwen;
}
}
xunwen:
{
char ch;
cout<<"是否繼續?是Y/否N"<<endl;
cin>>ch;
if (ch=='n' || ch=='N')
{
return s;
}
else
{
if (ch=='y' || ch=='Y')
{
goto wenti;
}
else
{
goto xunwen;
}
}
}
}
}
double division ()
{
double n,a,b,s;
wenti:
{
time(NULL);
srand(time(NULL));
a=rand()%100;
b=rand()%100;
s=a/b;
cout<<a<<"/"<<b<<"=?"<<endl;
cin>>n;
if(n==s)
{
cout<<"正确,你真聪明!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"结果不对,你再想想,你还有两次机会!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,继续保持!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,不要着急,要把握住最后一次机会喔!"<<endl;
}
}
cin>>n;
if(n==s)
{
cout<<"正确,加油!"<<endl;
goto xunwen;
}
else
{
if(n!=s)
{
cout<<"不正确,要加强练习喔!"<<" "<<"正确答案为:"<<s<< endl;
cout<<endl;
goto xunwen;
}
}
xunwen:
{
char ch;
cout<<"是否繼續?是Y/否N"<<endl;
cin>>ch;
if (ch=='n' || ch=='N')
{
return s;
}
else
{
if (ch=='y' || ch=='Y')
{
goto wenti;
}
else
{
goto xunwen;
}
}
}
}
}
就是这样了
可是
可是
……
老师竟然说不能用……
!·#¥%……
没天理啊
说是可读性太差,我没容易吗,
又要从来,忙了一个下午想来想去还是 goto语句好用啊 ……
哎……
烦恼了