我是小白一枚,求帮助
自己编的代码,但运行之后,总会输出错误,答案对了也是错误,不知道哪出了问题,求高手指点:#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(){
int x,y,symbol,ans;
int n,temp,sum=0;
srand(time(0));
for(int i=1;i<=10;i++)
{
x=rand()%9+1;
y=rand()%9+1;
symbol=rand()%2;
if(x<y&&symbol==1)
{
temp=x;
x=y;
y=temp;
}
} switch(symbol)
{
case 0:
ans=x+y;
cout<<x<<'-'<<y<<'=';break;
}
cin>>n;
if(n==ans)
{
sum+=10;
cout<<"正确"<<endl;
}
else
cout<<"错误"<<endl;
cout<<"得分:"<<sum<<endl;
return 0;
}