// computer y in terms of x
// from -4 until 3
#include <iostream>
# include <cmath>
usingnamespace std;
int main()
{
double x, result;
cout << "\tX VALUES\tY VALUES\t\tSTATUS"
<< endl << endl;
for (x = -4; x <=3; x= x + 0.5 ) {
result = (x*x*x*x - x*x*x - (7*(x*x)) + x + 6)/
(fabs(x - 3) + sqrt(5 - x));
cout << '\t' << x << "\t\t" << result;
if (result > 0)
{cout << "\t\t\tY IS POSITIVE";
cout << endl;
}
if (result=0)
{cout << "\t\t\tY IS ZERO";
cout << endl;
}
if (result < 0)
{cout << "\t\t\tY IS NEGATIVE";
cout << endl;
}
}
return 0;
}
X VALUES Y VALUES STATUS
-4 21 Y IS POSITIVE
-3.5 11.6497 Y IS POSITIVE
-3 5.43698 Y IS POSITIVE
-2.5 1.75242 Y IS POSITIVE
-2 0 -1.5 -0.398964 -1
0 -0.5 0.673629 Y IS POSITIVE
0 1.1459 Y IS POSITIVE
0.5 1.01432 Y IS POSITIVE
1 0 1.5 -1.94685 2
-4.3923 2.5 -5.67598 3 0
--------------------------------
Process exited with return value 0
Press any key to continue . . .
Well, there are two ways of answering, the first is what is the compiler trying to say, and the second is what should you do about it.
A "truth value" is a value which can be either true or false, in this case it is the value being tested in the if statement. An "assignment" is when a value is assigned to a variable, such as x = -4 or result = 0, in each case the variable on the left of the '=' sign is given the value of whatever expression is to the right of the '='.
The compiler is suggesting that you can fix the problem by adding parentheses. In this case it would mean the code was changed from if (result=0) to if ((result=0)). What does it mean? The compiler is trying to say that the code looks suspicious and is quite probably an error. If you really do want an assignment here, then the extra parentheses will confirm that you meant it and the message will go away. But - that is the wrong action to take - in this case the correct action is to replace the assignment operator '=' with the test for "is equal to", '=='.
Hope that helps.