From bd535955958ccc98de05591f66ee3679e48175a8 Mon Sep 17 00:00:00 2001 From: moonleay Date: Mon, 18 Nov 2024 17:08:16 +0100 Subject: [PATCH] feat: created base --- main.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 83a668a..ebc6bb2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,43 @@ #include "std_lib_inc.h" +const vector first_digit_strings = { +"", "ein", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun" +}; + +const vector middle_digit_strings = { +"", "zehn", "zwanzig", "deissig", "vierzig", "fuenfzig", "sechzig", "siebzig", "achzig", "neunzig" +}; + int main() { + int input; + // ReSharper disable once CppDFAEndlessLoop + while (true) + { + cin >> input; + if (!cin) + break; + if (input < 1 || input > 999) + { + cout << "Zahl ausserhalb des gueltigen Bereichs.\n"; + continue; + } + int input_length = static_cast(std::to_string(input).length()); + int first_digit = input % 10; + vector result; + result.push_back(first_digit_strings[first_digit]); + + int middle_digit = ((input % 100) - first_digit) / 10; + result.push_back(middle_digit_strings[middle_digit]); + + if (input_length == 3) + { + int last_digit = ((input % 1000) - middle_digit) / 100; + result.push_back(first_digit_strings[last_digit] + "hundert"); + } + + cout << result[2] << result[0] << "und" << result[1] << "\n"; + } + cout << "Eingabe beendet.\n"; return 0; -} \ No newline at end of file +}