tutorial.cxx 775 B

123456789101112131415161718192021222324252627
  1. // A simple program that computes the square root of a number
  2. #include <cmath>
  3. #include <cstdlib> // TODO 5: Remove this line
  4. #include <iostream>
  5. #include <string>
  6. // TODO 11: Include TutorialConfig.h
  7. int main(int argc, char* argv[])
  8. {
  9. if (argc < 2) {
  10. // TODO 12: Create a print statement using Tutorial_VERSION_MAJOR
  11. // and Tutorial_VERSION_MINOR
  12. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  13. return 1;
  14. }
  15. // convert input to double
  16. // TODO 4: Replace atof(argv[1]) with std::stod(argv[1])
  17. double const inputValue = atof(argv[1]);
  18. // calculate square root
  19. double const outputValue = sqrt(inputValue);
  20. std::cout << "The square root of " << inputValue << " is " << outputValue
  21. << std::endl;
  22. return 0;
  23. }