I am trying to create a quadratic equation program that also places the output in a .txt file. This is my program right now. It compiles but it places the answer in the form <2.4, 0> <0,5.4> and i need the answer to look like 2.4 5.4
Also I cannot figure out how to put the answers in order from least to greatest because when i try and put in another if statement such as if ( x1 << x2) cout << x1, x2; except it underlines the << and gives me the error message "NO OPERANDS MATCH THIS OPERATOR"....how can i fix this problem?? :( Thanks!
You are using complex numbers, so the default output for a number should look like (a,b), where a is the real and b is the imaginary part. If you want some other output format, you can access the a real and imaginary part using real() and imag() member functions.[1]
A quadratic equation doesn't have real root(s) iff b^2-4ac < 0.
The less than comparison operator is simply <, not <<. Also note that complex numbers doesn't have comparison operators defined.
Ohh I see. Okay i can leave the answer in that format but how do i define the comparison operators then? I thought that including c math would automatically include all operators
There is no obvious way to sort points in (the complex) plain. Which is bigger (1,2) or (0,3) ?
You can compare the real parts1, or the imaginary parts2, or the distance from the origin3 etc...
That Worked! Thanks! Okay so this is my code now and the only thing thats not making sense is how i make the no real roots statement apply to program4.txt also?
Also, I need the same statement " if (x1.real() < x2.real()) cout << x1 << x2 " to apply to the answer that I read out to program 4 but it messes up when i try and put an if statement in after program 4 << so where would i be able to place that?