+ 4
Why it is Giving garbage value
adding complex number https://code.sololearn.com/cmrkkHlau944/?ref=app
5 ответов
+ 12
Your methods have return type double but returns nothing. Your methods contain cout instructions but your main function calls the methods within another cout statement, causing errors.
This is what you should do:
#include <iostream>
using namespace std;
class complex{
public:
double addreal(double x,double y)
{return (x+y);}
double addimg(double p,double q)
{return (p+q);}
};
int main() {
complex obj;
cout<<obj.addreal(5,2)<<"+"<<"i"<<obj.addimg(5,3);
return 0;
}
+ 12
Your function is of type double.
Your function must have return value.
Your function has no return value.
Your function only has cout.
Your function must return value, not cout.
So, remove cout and replace with return statement.
+ 12
If you use void, you don't need to cout.
In main, do:
obj.addreal(5,2);
cout << "+i";
obj.addimg(5,3);
// if return type is void.
+ 4
thanks@hatsy rei
+ 2
if I use void instead of double
error is coming in cout statement in main function