| 1 |
// A simple program that computes the square root of a number |
| 2 |
#include <cmath> |
| 3 |
#include <iostream> |
| 4 |
#include <string> |
| 5 |
|
| 6 |
// TODO8: Include the MathFunctions header |
| 7 |
|
| 8 |
int main(int argc, char* argv[]) |
| 9 |
{ |
| 10 |
if (argc < 2) { |
| 11 |
std::cout << "Usage: " << argv[0] << " number" << std::endl; |
| 12 |
return 1; |
| 13 |
} |
| 14 |
|
| 15 |
// convert input to double |
| 16 |
double const inputValue = std::stod(argv[1]); |
| 17 |
|
| 18 |
// TODO9: Use the mathfunctions::sqrt function |
| 19 |
// calculate square root |
| 20 |
double const outputValue = std::sqrt(inputValue); |
| 21 |
std::cout << "The square root of " << inputValue << " is " << outputValue |
| 22 |
<< std::endl; |
| 23 |
} |