NOTE: in mathematics, the square root of a negative number is not real; in C++ therefore, passing such a value to the square root function is an error. Given a double variable named areaOfSquare write the necessary code to read in a value, the area of some square, into areaOfSquare and print out the length of the side of that square. HOWEVER: if any value read in is not valid input, just print the message "INVALID".

Answer :

Answer:

1 #include <iostream>

2 #include <cstring>

3 #include <cmath>

4  

5 #include <iomanip>

6  

7 using namespace std;

8  

9 int main () {

10  double areaOfSquare;

11  

12 cin >> areaOfSquare;

13  

14  if(areaOfSquare >= 0)

15    {

16    sqrt(areaOfSquare);

17    cout << areaOfSquare << endl;

18    }

19  else

20    {

21    cout << "INVALID" << endl;  

22    }

23  

24  

25 }

Other Questions