双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

illegal else without matching if可我找不出错误

leveldd leveldd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;};
void set(){cin>>real>>imag;}
bool operator==(Complex&c2);
void display();
double real;
double imag;
};
bool Complex::operator==(Complex&c2)
{
Complex c;
if(c.real==c2.real&&c.imag==c2.imag) return true;
else return false;
}
void Complex::display()
{
if(real==0)
{
if(imag!=0) cout<<imag<<"i,";
else cout<<"0,";
};
else
{
if(imag>0) cout<<real<<"+"<<imag<<"i,";
else if(imag<0) cout<<real<<imag<<"i,";
else cout<<real<<",";
};
}
int main()
{
Complex c1,c2;
c1.set();
c2.set();
while (c1.real!=0||c1.imag!=0||c2.real!=0||c2.imag!=0)
{
cout<<"a=";
c1.display();
cout<<"b=";
c2.display();
if (c1==c2) cout<<"a等于b"<<endl;
else
{
cout<<"a不等于b"<<endl;
};
c1.set();
c2.set();
}
return 0;
}


一直显示error C2181: illegal else without matching if

可我检查了好多遍也没检查出错误。。。到底是哪里出问题了。。不是都配对的好好的嘛~~~欲哭无泪 求救哇~~
...全文
评论 7
收藏 已收藏
分享
返回顶部
leveldd
C++ 语言 65,214 成员 250,514 内容