practice_geomethicMeandian/cpp_impl/src/main.cpp

40 lines
858 B
C++
Raw Normal View History

2021-05-01 13:31:59 +00:00
#include <cstdlib>
#include <cstdio>
#include "geometric_mean.hpp"
#include "geothmetic_meandian.hpp"
2021-05-01 12:29:05 +00:00
int main(int argc, char **argv) {
2021-05-01 13:31:59 +00:00
--argc; ++argv;
std::vector<double> input;
double temp;
while(argc > 0) {
temp = std::strtod(argv[0], nullptr);
if(temp == 0.0) {
puts("ERROR: Failed to parse double");
return 1;
} else {
input.push_back(temp);
}
--argc; ++argv;
}
printf("Got input:\n ");
for(double d : input) {
printf("%f ", d);
}
puts("");
if(input.size() == 2) {
printf("Geometric Mean of two doubles is %f\n",
geometric_mean(input[0], input[1]));
} else if(input.size() > 2) {
printf("Geomethic Meandian of input is %f\n",
geothmetic_meandian(input));
}
2021-05-01 12:29:05 +00:00
return 0;
}