epr24pr1_ojanssen2/main.cpp

54 lines
1.6 KiB
C++

#include "std_lib_inc.h"
const vector<string> first_digit_strings = {
"", "ein", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun"
};
const vector<string> 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<int>(std::to_string(input).length());
int first_digit = input % 10;
int middle_digit = ((input % 100) - first_digit) / 10;
vector<string> result;
string suffix = "";
if (first_digit == 1)
suffix = "s";
if (middle_digit != 0 && first_digit != 0)
suffix = "und";
result.push_back(first_digit_strings[first_digit] + suffix);
if (input_length > 1)
result.push_back(middle_digit_strings[middle_digit]);
else
result.push_back("");
if (input_length == 3)
{
int last_digit = ((input % 1000) - middle_digit) / 100;
string suffix = "";
result.push_back(first_digit_strings[last_digit] + "hundert" + suffix);
}
else
result.push_back("");
cout << result[2] << result[0] << result[1] << "\n";
}
cout << "Eingabe beendet.\n";
return 0;
}