Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int ziffer(int);
  9. void textual(int);
  10.  
  11. int main() {
  12.  
  13.     cout << "-----------------------------------------------------------------------------------------------------------" << endl;
  14.     cout << "------------------     Sprachliche Repräsentation von einer 4-stelligen ganzen Zahl   ---------------------" << endl;
  15.     cout << "-----------------------------------------------------------------------------------------------------------" << endl;
  16.  
  17.     int n;
  18.  
  19.     do {
  20.         cout << "Geben Sie eine 4-stellige Zahl ein(0 für Ende): ";
  21.         cin >> n;
  22.         cin.ignore(INT_MAX, '\n');
  23.    
  24.         if(n == 0) break;
  25.         else if(ziffer(n) != 4) {
  26.             cout << "Falsche Eingabe\n";
  27.             continue;
  28.         }
  29.    
  30.         textual(n);
  31.    
  32.     } while(n != 0);
  33.    
  34.     return 0;
  35. }
  36.  
  37. int ziffer(int n) {
  38.     int count{0};
  39.    
  40.     while(n != 0){
  41.         count++;
  42.         n /= 10;
  43.     }
  44.    
  45.     return count;
  46. }
  47.  
  48. void textual(int n) {
  49.     int count = ziffer(n);
  50.    
  51.     vector<string> v;
  52.    
  53.     for(int i = 0; i < count; i++) {
  54.    
  55.         switch(n % 10){
  56.             case 0:
  57.                 v.push_back("null");   
  58.             break;
  59.             case 1:
  60.                 v.push_back("eins");
  61.             break;
  62.             case 2:
  63.                 v.push_back("zwei");
  64.             break;
  65.             case 3:
  66.                 v.push_back("drei");
  67.             break;
  68.             case 4:
  69.                 v.push_back("vier");
  70.             break;
  71.             case 5:
  72.                 v.push_back("fünf");
  73.             break;
  74.             case 6:
  75.                 v.push_back("sechs");
  76.             break;
  77.             case 7:
  78.                 v.push_back("sieben");
  79.             break;
  80.             case 8:
  81.                 v.push_back("acht");
  82.             break;
  83.             case 9:
  84.                 v.push_back("neun");
  85.             break;     
  86.         }
  87.        
  88.         n /= 10;
  89.     }
  90.    
  91.     for(int i = count - 1; i >= 0; i--) {
  92.         cout << v.at(i);
  93.         if(i != 0) cout << "-";
  94.     }
  95.    
  96.     cout << endl;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement