From 5414e495c1e055a7ba3701b9b18e9442b35fce03 Mon Sep 17 00:00:00 2001 From: WDF-VIORuleZ Date: Sun, 28 Oct 2018 21:16:07 +0100 Subject: [PATCH] adding recursive countdown function --- c++/countdwon.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 c++/countdwon.cpp diff --git a/c++/countdwon.cpp b/c++/countdwon.cpp new file mode 100644 index 0000000..7d23013 --- /dev/null +++ b/c++/countdwon.cpp @@ -0,0 +1,30 @@ +#include +#include + +unsigned short countdown(unsigned short num) +{ + if(!num) + { + std::cout << num << std::endl; + return countdown(num--); + } + else + { + std::cerr << "Boooom" << std::endl; + exit(-1); + } +} + +int main(int argc, char const *argv[]) +{ + if(argc == 2) + { + countdown(static_castargv[1]); + return EXIT_SUCCESS; + } + else + { + std::cerr << "usage: countdown [NUM]" << std::endl; + return EXIT_FAILURE; + } +}