# Answer to Question #4711 in C++ for Rajveer

Question #4711

Write a C++ programme to calculate the value of function f(x)=x2+1.5x+5/x-3 for x=-10to 10, x should take values -10,-8,-6,....,6,8,10

Expert's answer

# include <iostream>

# include <cmath>

using namespace std;

int func()

{

int x;

double y = 0;

cout<<"Enter x, x [-10,10]: ";

cin>>x;

if (x < -10 || x > 10 || x == 0 || x/2 == 0)//it's for all numbers that don't meet requirements of the program

{

& cout<<"You've entered wrong number"<<endl;

& return -1;

}

else

{

y = x*x + 1.5*x + (double)5/x - 3 ;//our function

}

cout<<"f(x) = "<<y<<endl;

return y;

}

int main()

{

func();

system ("PAUSE");

return 0;

}

# include <cmath>

using namespace std;

int func()

{

int x;

double y = 0;

cout<<"Enter x, x [-10,10]: ";

cin>>x;

if (x < -10 || x > 10 || x == 0 || x/2 == 0)//it's for all numbers that don't meet requirements of the program

{

& cout<<"You've entered wrong number"<<endl;

& return -1;

}

else

{

y = x*x + 1.5*x + (double)5/x - 3 ;//our function

}

cout<<"f(x) = "<<y<<endl;

return y;

}

int main()

{

func();

system ("PAUSE");

return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment