tutorial.cxx 741 Bytes
Newer Older
Ken Martin's avatar
Ken Martin committed
1
// A simple program that computes the square root of a number
2 3 4 5
#include <cmath>
#include <iostream>
#include <string>

6
#include "TutorialConfig.h"
Ken Martin's avatar
Ken Martin committed
7 8

#ifdef USE_MYMATH
9
#  include "MathFunctions.h"
Ken Martin's avatar
Ken Martin committed
10 11
#endif

12
int main(int argc, char* argv[])
Ken Martin's avatar
Ken Martin committed
13
{
14
  if (argc < 2) {
15
    std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
16
              << Tutorial_VERSION_MINOR << std::endl;
17
    std::cout << "Usage: " << argv[0] << " number" << std::endl;
Ken Martin's avatar
Ken Martin committed
18
    return 1;
19
  }
Ken Martin's avatar
Ken Martin committed
20

21
  double inputValue = std::stod(argv[1]);
Ken Martin's avatar
Ken Martin committed
22 23

#ifdef USE_MYMATH
24
  double outputValue = mysqrt(inputValue);
Ken Martin's avatar
Ken Martin committed
25
#else
26
  double outputValue = sqrt(inputValue);
Ken Martin's avatar
Ken Martin committed
27 28
#endif

29 30
  std::cout << "The square root of " << inputValue << " is " << outputValue
            << std::endl;
Ken Martin's avatar
Ken Martin committed
31 32
  return 0;
}