Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Help / guide / tutorial / Step1 / tutorial.cxx
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
7 // TODO 11: Include TutorialConfig.h
8
9 int main(int argc, char* argv[])
10 {
11   if (argc < 2) {
12     // TODO 12: Create a print statement using Tutorial_VERSION_MAJOR
13     //          and Tutorial_VERSION_MINOR
14     std::cout << "Usage: " << argv[0] << " number" << std::endl;
15     return 1;
16   }
17
18   // convert input to double
19   // TODO 4: Replace atof(argv[1]) with std::stod(argv[1])
20   const double inputValue = atof(argv[1]);
21
22   // calculate square root
23   const double outputValue = sqrt(inputValue);
24   std::cout << "The square root of " << inputValue << " is " << outputValue
25             << std::endl;
26   return 0;
27 }