Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <climits>
- #include <string>
- #include <vector>
- using namespace std;
- int ziffer(int);
- void textual(int);
- int main() {
- cout << "-----------------------------------------------------------------------------------------------------------" << endl;
- cout << "------------------ Sprachliche Repräsentation von einer 4-stelligen ganzen Zahl ---------------------" << endl;
- cout << "-----------------------------------------------------------------------------------------------------------" << endl;
- int n;
- do {
- cout << "Geben Sie eine 4-stellige Zahl ein(0 für Ende): ";
- cin >> n;
- cin.ignore(INT_MAX, '\n');
- if(n == 0) break;
- else if(ziffer(n) != 4) {
- cout << "Falsche Eingabe\n";
- continue;
- }
- textual(n);
- } while(n != 0);
- return 0;
- }
- int ziffer(int n) {
- int count{0};
- while(n != 0){
- count++;
- n /= 10;
- }
- return count;
- }
- void textual(int n) {
- int count = ziffer(n);
- vector<string> v;
- for(int i = 0; i < count; i++) {
- switch(n % 10){
- case 0:
- v.push_back("null");
- break;
- case 1:
- v.push_back("eins");
- break;
- case 2:
- v.push_back("zwei");
- break;
- case 3:
- v.push_back("drei");
- break;
- case 4:
- v.push_back("vier");
- break;
- case 5:
- v.push_back("fünf");
- break;
- case 6:
- v.push_back("sechs");
- break;
- case 7:
- v.push_back("sieben");
- break;
- case 8:
- v.push_back("acht");
- break;
- case 9:
- v.push_back("neun");
- break;
- }
- n /= 10;
- }
- for(int i = count - 1; i >= 0; i--) {
- cout << v.at(i);
- if(i != 0) cout << "-";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement