First, please use code tags when posting code. See
http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post.
Pay attention to whitespace and indentation. When done intuitively, the various scopes are easier to see.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
if (initialvalue <= endingvalue)
{
cout << " x functional value" << endl;
cout << "============================================" << endl;
}
for (x = initialvalue; x <= endingvalue; x += increment)
{
f = pow(e, -x)*(x + 3)*cos(2*x);
cout << setw(5) << fixed << setprecision(1) << x << setw(30)
<< fixed << setprecision(2) << f << endl;
}
if (f < 0)
{
cout << f << "***" << endl;
}
|
You do have a (conditional) header of the table. Nice. However, you do know that initialvalue <= endingvalue, so there is not much uncertainty.
Your loop counter is a double. That may or may not work, for floating point math in computer is not quite as intuitive as theoretical math. As a guideline prefer integral loop counter and compute a double value from it.
You have a table.
One line should have x, f(x) and *** (if f(x) is negative).
Your table does not have those. It has only x and f(x).
Then you print one separate line of ***, if the last f(x) was negative.
Not quite what was requested.
Minimum value. You have to keep track (i.e. store) of a x,f(x) pair that was small. On every iteration, if the current f(x) is less, then update that stored pair.
What is are good initial values for x and f(x) before the loop starts?