I'm working on problem 6 of Euler but the issue I'm having isn't necessarily related to the answer to the problem. I'm attempting to solve the problem using OOP because I really need to get better at it and I keep receiving this error after trying to compile:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Euler6' (or there is no acceptable conversion)
Edit: there are other approaches... like:
- making your float x; public and simply cout << z.x;
- writing a conversion operator like operatorfloat() const {return x;}
I also fixed the infinite loops I had above and they are producing the correct results but how do I get them to send the correct numbers back to the main program. When I run the program and debug it, it shows that the correct values are going into sum but when I return sum the value of x and y becomes 1 and it keeps saying my difference is zero.
You never assign the sum value to anything persistent. You calculate the sum value in a local value in each function, and then return the sum. The returned value is ignored (you never do anything with it.) You never re-assigned the x value in either "x" or "y" (by the way, consider renaming something so you don't have "x" as an Euler6 object and "x" and as a data member).
So, when you return from the 2 function calls, "x" and "y" are unchanged.
You must either modify ".x" in your functions or capture the return values from the function calls.