Use [code][/code] tags.
Format your code, what you have now is ugly.
Isn't this much nicer? ( you can use
http://format.krzaq.cc/ to do this easily )
Code
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double result, val;
cout << "this is the output of my first program" << endl;
for (val = -3.0; val <= 5.0; val += 0.5)
{
result = (-4.0 * val * val * val + 8.0 * val * val + 9.0 * val + 18)
/ (abs(7.0 - val * val * val) + (sqrt(3.0 * val * val + 10)));
cout << "val =" << val << "result =" << result << endl;
}
if (result = 0.0)
cout << "result is zero" << endl;
if (result > 0.0)
cout << "result is positive" << endl;
if (result < 0.0)
cout << "result is negative" << endl;
cout << "The program is finished";
return 0;
}
Finally:
if (result = 0.0) -- a single
= is an assignment, not comparison.
== is comparison, but you're using floating point numbers, and with those, exact comparison is almost always incorrect. You should check if the result is within an epsion of 0, for example:
Code
double const epsilon = 0.001;
if (abs(result) < epsilon)
cout << "result is zero" << endl;
else if (result > 0.0)
cout << "result is positive" << endl;
else if (result < 0.0)
cout << "result is negative" << endl;
This post was edited by KrzaQ2 on Sep 9 2015 04:30pm