Hello please help me.

I need some help with this program.
The task is to write a complete program that evaluate a formula in terms of y and x. The formula is y=x*x*x*x-x*x*x-7*x*x+x+6/(abs(x-))+sqrt(5-x)
the program should evaluate the formula starting with x=-4. going up by 0.5 until reaches 3 . If value of y is 0, the message after output should be Y IS 0, if the value of y is positive, the message should say is positive, if the value of y is negative, the message should say y is negative/

In addiction to the above:
Have your program find which of the y values is closest to 1. Have the program print the x value that gives this closest y value. Also print how close y value is to 1/ Have your program count how many times the formula is positive, negative and how many times it is zero.
I have trouble with in addition part.
here is the code i have so far.

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,y;
cout<<"\t\tTable of Function Values"<<endl<<endl;
for (x=-3;x<=4;x=x+0.5)
{
y=(x*x*x*x-x*x*x-7*x*x+x+6)/(abs(x-3)+sqrt(5-x));
cout<<'\t'<<x<<"\t\t"<<y;
if (y==0)
cout<< "\t\t Y is Zero"<<endl;
if (y<0)
cout<<"\t Y is negative"<<endl;
if (y>0)
cout<<"\t\t Y is positive"<<endl;
cout <<endl;

}
cout <<endl<< "The table is finished"<<endl;
return 0;
}

Please help me find which of the y values is closest to 1. Have the program print the x value that gives this closest y value. Also print how close y value is to 1/ Have your program count how many times the formula is positive, negative and how many times it is zero.
I have trouble with in addition part.
here is the code i have so far. Your help will be appreciated thank you.


The "positive, negative, zero" counters: Count is obviously 0 before your loop. Count should increase by one every time the condition is true. After the loop the count should thus hold the expected value.

"closest to 1", this is similar to "find maximum element of an array". You must store a pair (x,diff). Every time you compute a new y, you do compute diff between y and 1.0 too. If that diff is better than the stored diff, then you update the (x,diff). After the loop you should thus have the correct answer to those two questions.
Topic archived. No new replies allowed.