#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", "dreissig", "vierzig", "fuenfzig", "sechzig", "siebzig", "achzig", "neunzig" }; int main() { int input; /* * Use while (true) with break instead of while(cin) to be able to instantly stop the loop in case of an invalid input */ while (true) { cin >> input; if (!cin) break; // Stop running loop, if input is wrong if (input < 1 || input > 999) { cout << "Zahl ausserhalb des gueltigen Bereichs.\n"; continue; } const int right_digit = input % 10; const int middle_and_right_digit = input % 100; const int middle_digit = ((middle_and_right_digit) - right_digit) / 10; vector result; string number_construction = ""; if (middle_and_right_digit < 11 || middle_and_right_digit > 12) { // Handle everything else if (right_digit == 1) number_construction = "s"; if (middle_digit > 1 && right_digit != 0) number_construction = "und"; number_construction = first_digit_strings[right_digit] + number_construction; } else { // Handle 11 and 12 if (middle_and_right_digit == 11) number_construction = "elf"; else number_construction = "zwoelf"; } result.push_back(number_construction); if ((input > 9 /*input_length > 1*/) && (middle_and_right_digit < 11 || middle_and_right_digit > 12)) result.push_back(middle_digit_strings[middle_digit]); else result.push_back(""); if (input > 99 /*input_length >= 3*/) { int left_digit = ((input % 1000) - middle_digit) / 100; if (left_digit != 1) number_construction = first_digit_strings[left_digit]; else number_construction = ""; result.push_back(number_construction + "hundert"); } else result.push_back(""); cout << result[2] << result[0] << result[1] << "\n"; } cout << "Eingabe beendet.\n"; return 0; }