Tutorial.cxx 666 B

1234567891011121314151617181920212223242526
  1. // A simple program that computes the square root of a number
  2. // TODO3: 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. // TODO4: Convert the print to use std::format
  10. std::cout << "Usage: " << argv[0] << " number" << std::endl;
  11. return 1;
  12. }
  13. // convert input to double
  14. double const inputValue = std::stod(argv[1]);
  15. // calculate square root
  16. double const outputValue = mathfunctions::sqrt(inputValue);
  17. // TODO5: Convert the print to use std::format
  18. std::cout << "The square root of " << inputValue << " is " << outputValue
  19. << std::endl;
  20. }