tutorial.cxx 760 B

123456789101112131415161718192021222324252627282930313233
  1. // A simple program that computes the square root of a number
  2. #include <cmath>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6. #include "TutorialConfig.h"
  7. #ifdef USE_MYMATH
  8. # include "MathFunctions.h"
  9. #endif
  10. int main(int argc, char* argv[])
  11. {
  12. if (argc < 2) {
  13. std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
  14. << Tutorial_VERSION_MAJOR << std::endl;
  15. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  16. return 1;
  17. }
  18. double inputValue = std::stod(argv[1]);
  19. #ifdef USE_MYMATH
  20. double outputValue = mysqrt(inputValue);
  21. #else
  22. double outputValue = sqrt(inputValue);
  23. #endif
  24. std::cout << "The square root of " << inputValue << " is " << outputValue
  25. << std::endl;
  26. return 0;
  27. }