Tutorial.cxx 747 B

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