输入符号后结束不了程序,怎么办
#include<iostream>#include<cstdlib>
using namespace std;
class imaginary
{ double x,y;
public:
imaginary(double a=0,double b=0):x(a),y(b){};
friend imaginary add(imaginary c,imaginary d);
friend imaginary sub(imaginary e,imaginary f);
friend imaginary mul(imaginary g,imaginary h);
friend imaginary div(imaginary m,imaginary n);
friend ostream & operator<<(ostream &output,imaginary &v);
void show(imaginary p,imaginary q,int w);
};
imaginary add(imaginary c,imaginary d)
{ imaginary ad;
ad.x=c.x+d.x;
ad.y=c.y+d.y;
return ad;
}
imaginary sub(imaginary e,imaginary f)
{ imaginary su;
su.x=e.x-f.x;
su.y=e.y-f.y;
return su;
}
imaginary mul(imaginary g,imaginary h)
{ imaginary mu;
mu.x=(g.x*h.x)-(g.y*h.y);
mu.y=(g.x*h.y)+(g.y*h.x);
return mu;
}
imaginary div(imaginary m,imaginary n)
{ imaginary di;
di.x=(m.x*n.x+m.y*n.y)/(n.x*n.x+n.y*n.y);
di.y=(m.y*n.x-m.x*n.y)/(n.x*n.x+n.y*n.y);
return di;
}
ostream & operator<<(ostream & output,imaginary &v)
{ output<<v.x<<"+"<<v.y<<"i";
return output;
}
void imaginary::show(imaginary p,imaginary q,int w)
{ switch(w)
{ case 0:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"+"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<add(p,q)<<endl;break;
case 1:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"-"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<sub(p,q)<<endl;break;
case 2:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"*"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<mul(p,q)<<endl;break;
case 3:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"/"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<div(p,q)<<endl;
}
}
void main()
{ imaginary im;
imaginary j(1,2),i(3,4);
char a={0};
int r,flag;
cout<<"i=3+4i,j=1+2i."<<'\n'<<"Please input i and j 's operation symbol:";
while(cin>>a)
{ flag=1;
if(a=='+') r=0;
else if(a=='-') r=1;
else if(a=='*') r=2;
else if(a=='/') r=3;
else { flag=0;cout<<"Wrong symbol!"<<endl;}
if(flag)
{ im.show(i,j,r);
}
}
system("pause");
}
如题,输入符号显示输出后仍留在输入界面,要加些什么代码才可结束程序?