Tutorial.cxx 609 B

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