在if里面如果除数为0就显示“除数不能为0”,除数不为0就输出答案,if条件要怎么写


#include<iostream>
using namespace std;
class complex
{
    double real, image;
public:
    complex() { real = 0; image = 0; }
    complex(double r , double i )
    {real = r; image = i;}
    void show()
    {
        cout << real << "+(" << image << ")i" << endl;
    }
    
    complex operator/(complex& op3)
    {
        complex temp;
        temp.real = (real * op3.real + image * op3.image) / (op3.real * op3.real + op3.image * op3.image);
        temp.image = (image * op3.real - real * op3.image) / (op3.real * op3.real + op3.image * op3.image);
        return temp;
    }
};
#include<iostream>
using namespace std;
#include"asd.h"
void main()
{
    complex ob1(1.5, 3.0);
    complex ob2(0, 0);
    complex sum;
    sum = ob1 / ob2;
    cout << "复数1为" << endl;
    ob1.show();
    cout << "复数2为" << endl; 
    ob2.show();
    if (ob1==(0,0))
    {
        cout << "除数不能等于0" << endl;

    }
    else
    cout << "结果为" << endl;
    sum.show();
}

img

先判断 一下除数是不是等于0, 加一个&&判断,再进行除法运算

实部、虚部分开判断,并且都为0