diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | main.cpp | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..0f41258 --- /dev/null +++ b/main.cpp @@ -0,0 +1,37 @@ +#include <iostream> +#include <iomanip> +#include <limits> + +int main(int argc, char *argv[]){ + if(argc==2) { + std::cout << std::fixed; + float printable{std::stof(argv[1])}; + std::cout << std::setprecision(std::numeric_limits<float>::max_digits10 + 2); + std::cout << printable << std::endl; + } else if(argc==3) { + std::string floatsize{argv[2]}; + if(floatsize=="f") { + std::cout << std::fixed; + float printable{std::stof(argv[1])}; + std::cout << std::setprecision(std::numeric_limits<float>::max_digits10 + 2); + std::cout << printable << std::endl; + } else if (floatsize=="d") { + std::cout << std::fixed; + double printable{std::stod(argv[1])}; + std::cout << std::setprecision(std::numeric_limits<double>::max_digits10 + 2); + std::cout << printable << std::endl; + } else if (floatsize=="ld") { + std::cout << std::fixed; + long double printable{std::stold(argv[1])}; + std::cout << std::setprecision(std::numeric_limits<long double>::max_digits10 + 2); + std::cout << printable << std::endl; + } else { + std::cerr << "That's not a valid floatsize. The only valid sizes are: f, d and ld." << std::endl; + return 1; + } + } else { + std::cerr << "Incorrect number of arguments." << std::endl; + return 1; + } + return 0; +} |