cmake/Tests/Tutorial/Step5/tutorial.cxx

33 lines
741 B
C++
Raw Normal View History

// A simple program that computes the square root of a number
2019-11-11 23:01:05 +01:00
#include <cmath>
#include <iostream>
#include <string>
2016-07-09 11:21:54 +02:00
#include "TutorialConfig.h"
#ifdef USE_MYMATH
2018-08-09 18:06:22 +02:00
# include "MathFunctions.h"
#endif
2016-07-09 11:21:54 +02:00
int main(int argc, char* argv[])
{
2016-07-09 11:21:54 +02:00
if (argc < 2) {
2019-11-11 23:01:05 +01:00
std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
<< Tutorial_VERSION_MAJOR << std::endl;
std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
double inputValue = std::stod(argv[1]);
#ifdef USE_MYMATH
2019-11-11 23:01:05 +01:00
double outputValue = mysqrt(inputValue);
#else
2019-11-11 23:01:05 +01:00
double outputValue = sqrt(inputValue);
#endif
2019-11-11 23:01:05 +01:00
std::cout << "The square root of " << inputValue << " is " << outputValue
<< std::endl;
return 0;
}