08323bfac93c25cbea6ed529b35dfe5b36074296
[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>
4 #include <iostream>
5 #include <string>
6
7 int main(int argc, char* argv[])
8 {
9   if (argc < 2) {
10     std::cout << "Usage: " << argv[0] << " number" << std::endl;
11     return 1;
12   }
13
14   // convert input to double
15   const double inputValue = atof(argv[1]);
16
17   // calculate square root
18   const double outputValue = sqrt(inputValue);
19   std::cout << "The square root of " << inputValue << " is " << outputValue
20             << std::endl;
21   return 0;
22 }