You can include the <cmath> header so you can actually calculate the square root. I would start off something like this in terms of pseudo code
Declare a double to variable x and a variable result
Assign a value to x to initialise it like 0.0
Prompt the user using cout for a number they want to put into the formula
Use the cin command to get the number assigned to x
Assign the number you get for the equation to result
Use cout to display the answer for result
Yes this is my homework and i try a lot but can't solve this.
Plz if any one can solve it help me plz.
I have to submit it tomorrow..plz solve it.i will be grateful to you
#include <iostream>
#include <cmath>
int main()
{
std::cout << "Hello World!\n";
/*
I have given examples for each step I have provided, use them to write your own
Declare a double to variable x and a variable result (e.g. double y, sum)
Assign a value to x to initialise it like 0.0 (e.g. y = 0.0)
Prompt the user using cout for a number they want to put into the formula
(example - cout << "Text here")
Use the cin command to get the number assigned to x
(cin >> y)
Assign the number you get for the equation to result
(sum = 1 + y)
Use cout to display the answer for result
(cout << "The answer is = " << y << endl;)
*/
return 0;
}
Leave yourself plenty of time to do your homework. I am actually a teacher and poor organisation is your enemy I am sure!
don't overthink it..
sqrt (pow(x,3)+pow(x,2)-12*x-12)
is correct.
or just say
complex<double> f(complex<double> x){return sqrt(x*x*x+x*x-12*x-12);}
if you don't want to deal with complex, you can check that the sqrt is positive and if not print 'imaginary result' or something.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
// VARIABLES
double x = 0.0; // USER VALUE
double y = 0.0; // ANSWER
// PROMPT FOR INPUT FROM USER
cout << "Please enter a number: " << endl;
// GET VALUE FROM USER
cin >> x;
// PUT x IN EQUATION AND GET y
y = sqrt (pow(x,3)+pow(x,2)-12*x-12);
// PRINT ANSWER
cout << "Answer: " << y << endl;
return 0;
}
Please enter a number:
10.2
Answer: 32.1068
Program ended with exit code: 0