#include<iostream>
using namespace std;
int main()
{
int x,y,z,num=10,b,L,l=20;
double a;
char SET;
int i=0,score=0;
time_t t;
srand(time(&t));
cout<<" ============"<<endl;
cout<<" ★四则训练★"<<endl;
cout<<" ============"<<endl;
cout<<endl;
cout<<endl;
cout<<" ~~庚庚制作~~~"<<endl;
cout<<endl;
cout<<endl;
cout<<"是否进行设置 是 y 否 n"<<endl;
cin>>SET;
if(SET==y)
{
cout<<"请选择所需难度---简单 1 中等 2 困难 3 "<<endl;
cin>>L;
cout<<"请输入题目总数"<<endl;
cin>>num;
a=100/num;
cout<<endl;
if(L==1)
l=10;
else if(L==2)
l=20;
else
l=40;
while(i<num)
{
b=rand()%4;
if(b==0)
{
x=rand()%(2*l+1);
y=rand()%(2*l+1);
cout<<x<<" - "<<y<<" = ";
cin>>z;
if(x-y==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x-y<<endl;
score+=a;
i++;
cout<<endl;
}
}
else if(b==1)
{
x=rand()%(2*l+1);
y=rand()%(2*l+1);
cout<<x<<" + "<<y<<" = ";
cin>>z;
if(x+y==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x+y<<endl;
score+=0;
i++;
cout<<endl;
}
}
else if(b==2)
{ x=rand()%l;
y=rand()%l;
cout<<x<<" * "<<y<<" = ";
cin>>z;
if(x*y==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x*y<<endl;
score+=0;
i++;
cout<<endl;
}
}
else
{ x=rand()%l;
y=rand()%2;
cout<<x*(y+1)<<" / "<<y+1<<" = ";
cin>>z;
if(x==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x<<endl;
score+=0;
i++;
cout<<endl;
}
}
}
}
else
{
while(i<num)
{
b=rand()%4;
if(b==0)
{
x=rand()%(2*l+1);
y=rand()%(2*l+1);
cout<<x<<" - "<<y<<" = ";
cin>>z;
if(x-y==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x-y<<endl;
score+=a;
i++;
cout<<endl;
}
}
else if(b==1)
{
x=rand()%(2*l+1);
y=rand()%(2*l+1);
cout<<x<<" + "<<y<<" = ";
cin>>z;
if(x+y==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x+y<<endl;
score+=0;
i++;
cout<<endl;
}
}
else if(b==2)
{ x=rand()%l;
y=rand()%l;
cout<<x<<" * "<<y<<" = ";
cin>>z;
if(x*y==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x*y<<endl;
score+=0;
i++;
cout<<endl;
}
}
else
{ x=rand()%l;
y=rand()%2;
cout<<x*(y+1)<<" / "<<y+1<<" = ";
cin>>z;
if(x==z)
{ cout<<endl;
score+=a;
i++;
}
else
{
cout<<"对不起,错了,正确结果是:"<<x<<endl;
score+=0;
i++;
cout<<endl;
}
}
}
}
if(score>=90)
cout<<"您的成绩是:"<<score<<" 分 "<<"您是一个优秀的好学生"<<endl;
else if(score>=80)
cout<<"您的成绩是:"<<score<<" 分 "<<"您是一个良好的好学生"<<endl;
else if(score>=70)
cout<<"您的成绩是:"<<score<<" 分 "<<"您是一个中等的好学生"<<endl;
else if(score>=60)
cout<<"您的成绩是:"<<score<<" 分 "<<"您是一个囧的学生"<<endl;
else if(score<60)
cout<<"您的成绩是:"<<score<<" 分 "<<"唉,不得不说您是一个很笨的学生,笨死了~~您要好好学习,天天向上!"<<endl;
system("pause");
return 0;
}
不知道为什么运行的结果和我想像中的不一样,可是有不知道问题出在哪,我是一个C++初学者~~请高手看一下~~