cmake/Help/guide/tutorial/Step1/tutorial.cxx

28 lines
775 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>
2022-11-16 20:14:03 +01:00
#include <cstdlib> // TODO 5: Remove this line
2019-11-11 23:01:05 +01:00
#include <iostream>
#include <string>
2022-11-16 20:14:03 +01:00
// TODO 11: Include TutorialConfig.h
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) {
2022-11-16 20:14:03 +01:00
// TODO 12: Create a print statement using Tutorial_VERSION_MAJOR
// and Tutorial_VERSION_MINOR
2019-11-11 23:01:05 +01:00
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
2020-02-01 23:06:01 +01:00
// convert input to double
2022-11-16 20:14:03 +01:00
// TODO 4: Replace atof(argv[1]) with std::stod(argv[1])
2020-02-01 23:06:01 +01:00
const double inputValue = atof(argv[1]);
2019-11-11 23:01:05 +01:00
2020-02-01 23:06:01 +01:00
// calculate square root
const double outputValue = sqrt(inputValue);
2019-11-11 23:01:05 +01:00
std::cout << "The square root of " << inputValue << " is " << outputValue
<< std::endl;
return 0;
}