if statement problem

I think I got most of this right, but I figured I'd see what you professionals think.

Write an If statement that takes the square root of the variable area only when its value is non-negative. Otherwise, the statement should set area equal to its absolute value and then take the square root of the new value. The result should be assigned to the variable root.

1
2
3
4
5
6
7
8
9
10
if (area >= 0)
{
	root = sqrt(area)
	cout << root << endl;
}
else
{
	root = sqrt (|area|)
	cout << root << endl;
}


I believe I did this correctly, but we'll see. Any input would be fantastic.
To get the absolute value you need to use abs(area).
Reading this part of the assignment: Otherwise, the statement should set area equal to its absolute value I understand that you need to modify the value in 'area' ( area = abs(area); ) This will allow you to use the code calculating the root only once
Ohhh okay! Thank you. I was wondering if there was a specific thing for absolute value.
Topic archived. No new replies allowed.