C++ :: Aufgabe #288
2 Lösungen

Zahlen in Wörtern ausdrücken
Anfänger - C++
von Gisbert5020
- 30.04.2020 um 15:17 Uhr
Schreiben Sie ein Programm, das Zahlen von 0 bis 99 in Wörtern fasst.
Zusatzaufgabe : Erweitern Sie das Programm von 0 bis 1000.
Zusatzaufgabe : Erweitern Sie das Programm von 0 bis 1000.
Lösungen:

#include <iostream> #include <conio.h> #include <stdlib.h> #include <windows.h> #include <string> using namespace std;//durch Eingabe diueser Zeile muss der Computer nicht mehr in der void funk_10(); void funk_20(); int main (void) { funk_10(); cin.get(); //hält die Konsole offen wartet auf Enter return 0; } void funk_10() { string a = "und", z = "zehn", b = "zwanzig", c = "dreissig",d = "vierzig", e = "fuenfzig",f = "sechzig", g = "siebzig",h = "achzig", j = "neunzig", k = "hundert", ei = "ein",zw = "zwei",dr = "drei",vi = "vier",fue="fuenf",se="sechs",si="sieben",ac="acht",ne="neun",tau="tausend"; int wechsel; for(int Wiederholung=0; Wiederholung<=9; Wiederholung++) { for(int i=1; i<=100; i++) { if(Wiederholung==0) { cout<<"\nZahl "<<i<<" ist ausgeschrieben:"; } // int wechsel; wechsel = Wiederholung; if(((i!=100)&&(i>=10)&&(wechsel==1))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<ei<<k;} if(((i!=100)&&(i<10)&&(wechsel==1))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<ei<<k;} if((i==100)&&(wechsel==1)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<zw<<k;} if(((i!=100)&&(i>=10)&&(wechsel==2))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<zw<<k;} if(((i!=100)&&(i<10)&&(wechsel==2))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<zw<<k;} if((i==100)&&(wechsel==2)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<dr<<k;} if(((i!=100)&&(i>=10)&&(wechsel==3))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<dr<<k;} if(((i!=100)&&(i<10)&&(wechsel==3))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<dr<<k;} if((i==100)&&(wechsel==3)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<vi<<k;} if(((i!=100)&&(i>=10)&&(wechsel==4))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<vi<<k;} if(((i!=100)&&(i<10)&&(wechsel==4))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<vi<<k;} if((i==100)&&(wechsel==4)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<fue<<k;} if(((i!=100)&&(i>=10)&&(wechsel==5))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<fue<<k;} if(((i!=100)&&(i<10)&&(wechsel==5))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<fue<<k;} if((i==100)&&(wechsel==5)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<se<<k;} if(((i!=100)&&(i>=10)&&(wechsel==6))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<se<<k;} if(((i!=100)&&(i<10)&&(wechsel==6))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<se<<k;} if((i==100)&&(wechsel==6)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<si<<k;} if(((i!=100)&&(i>=10)&&(wechsel==7))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<si<<k;} if(((i!=100)&&(i<10)&&(wechsel==7))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<si<<k;} if((i==100)&&(wechsel==7)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<ac<<k;} if(((i!=100)&&(i>=10)&&(wechsel==8))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<ac<<k;} if(((i!=100)&&(i<10)&&(wechsel==8))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<ac<<k;} if((i==100)&&(wechsel==8)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<ne<<k;} if(((i!=100)&&(i>=10)&&(wechsel==9))){cout<<"\nZahl "<<wechsel<<i<<" ist ausgeschrieben: "<<ne<<k;} if(((i!=100)&&(i<10)&&(wechsel==9))){cout<<"\nZahl "<<wechsel*10<<i<<" ist ausgeschrieben: "<<ne<<k;} if((i==100)&&(wechsel==9)) {cout<<"\nZahl "<<((wechsel+1)*i)<<" ist ausgeschrieben: "<<tau;} if(((i==1)||(i==10)||(i==11)||(i==21)||(i==31)||(i==41)||(i==51)||(i==61)||(i==71)||(i==81)||(i==91))&&((i!=11)&&(i!=10))){ cout<<" "<<ei;} if (i==1){cout<<"s";} if (i==10){cout<<" "<<z;} if (i==11){cout<<" elf";} if (i==21){cout<<a<<b;} if (i==31){cout<<a<<c;} if (i==41){cout<<a<<d;} if (i==51){cout<<a<<e;} if (i==61){cout<<a<<f;} if (i==71){cout<<a<<g;} if (i==81){cout<<a<<h;} if (i==91){cout<<a<<j;} if(((i==2)||(i==12)||(i==20)||(i==22)||(i==32)||(i==42)||(i==52)||(i==62)||(i==72)||(i==82)||(i==92))&&((i!=20)&&(i!=12))){ cout<<" zwei";} if (i==2){;} if (i==12){cout<<" zwoelf";} if (i==20){cout<<" "<<b;} if (i==22){cout<<a<<b;} if (i==32){cout<<a<<c;} if (i==42){cout<<a<<d;} if (i==52){cout<<a<<e;} if (i==62){cout<<a<<f;} if (i==72){cout<<a<<g;} if (i==82){cout<<a<<h;} if (i==92){cout<<a<<j;} if(((i==3)||(i==30)||(i==13)||(i==23)||(i==33)||(i==43)||(i==53)||(i==63)||(i==73)||(i==83)||(i==93))&&(i!=30)){ cout<<" drei";} if (i==3){;} if (i==30){cout<<" "<<c;} if (i==13){cout<<z;} if (i==23){cout<<a<<b;} if (i==33){cout<<a<<c;} if (i==43){cout<<a<<d;} if (i==53){cout<<a<<e;} if (i==63){cout<<a<<f;} if (i==73){cout<<a<<g;} if (i==83){cout<<a<<h;} if (i==93){cout<<a<<j;} if(((i==4)||(i==40)||(i==14)||(i==24)||(i==34)||(i==44)||(i==54)||(i==64)||(i==74)||(i==84)||(i==94))&&(i!=40)){ cout<<" vier";} if (i==4){;} if (i==40){cout<<" "<<d;} if (i==14){cout<<z;} if (i==24){cout<<a<<b;} if (i==34){cout<<a<<c;} if (i==44){cout<<a<<d;} if (i==54){cout<<a<<e;} if (i==64){cout<<a<<f;} if (i==74){cout<<a<<g;} if (i==84){cout<<a<<h;} if (i==94){cout<<a<<j;} if(((i==5)||(i==50)||(i==15)||(i==25)||(i==35)||(i==45)||(i==55)||(i==65)||(i==75)||(i==85)||(i==95))&&(i!=50)){ cout<<" fuenf";} if (i==5){;} if (i==50){cout<<" "<<e;} if (i==15){cout<<z;} if (i==25){cout<<a<<b;} if (i==35){cout<<a<<c;} if (i==45){cout<<a<<d;} if (i==55){cout<<a<<e;} if (i==65){cout<<a<<f;} if (i==75){cout<<a<<g;} if (i==85){cout<<a<<h;} if (i==95){cout<<a<<j;} if(((i==6)||(i==60)||(i==16)||(i==26)||(i==36)||(i==46)||(i==56)||(i==66)||(i==76)||(i==86)||(i==96))&&((i!=60)&&(i!=16))){ cout<<" sechs";} if (i==6){;} if (i==60){cout<<" "<<f;} if (i==16){cout<<" sech"<<z;} if (i==26){cout<<a<<b;} if (i==36){cout<<a<<c;} if (i==46){cout<<a<<d;} if (i==56){cout<<a<<e;} if (i==66){cout<<a<<f;} if (i==76){cout<<a<<g;} if (i==86){cout<<a<<h;} if (i==96){cout<<a<<j;} if(((i==7)||(i==70)||(i==17)||(i==27)||(i==37)||(i==47)||(i==57)||(i==67)||(i==77)||(i==87)||(i==97))&&(i!=70)){ cout<<" sieben";} if (i==7){;} if (i==70){cout<<" "<<g;} if (i==17){cout<<z;} if (i==27){cout<<a<<b;} if (i==37){cout<<a<<c;} if (i==47){cout<<a<<d;} if (i==57){cout<<a<<e;} if (i==67){cout<<a<<f;} if (i==77){cout<<a<<g;} if (i==87){cout<<a<<h;} if (i==97){cout<<a<<j;} if(((i==8)||(i==80)||(i==18)||(i==28)||(i==38)||(i==48)||(i==58)||(i==68)||(i==78)||(i==88)||(i==98))&&(i!=80)){ cout<<" acht";} if (i==8){;} if (i==80){cout<<" "<<h;} if (i==18){cout<<z;} if (i==28){cout<<a<<b;} if (i==38){cout<<a<<c;} if (i==48){cout<<a<<d;} if (i==58){cout<<a<<e;} if (i==68){cout<<a<<f;} if (i==78){cout<<a<<g;} if (i==88){cout<<a<<h;} if (i==98){cout<<a<<j;} if(((i==9)||(i==90)||(i==19)||(i==29)||(i==39)||(i==49)||(i==59)||(i==69)||(i==79)||(i==89)||(i==99))&&(i!=90)){ cout<<" neun";} if (i==9){;} if (i==90){cout<<" "<<j;} if (i==19){cout<<z;} if (i==29){cout<<a<<b;} if (i==39){cout<<a<<c;} if (i==49){cout<<a<<d;} if (i==59){cout<<a<<e;} if (i==69){cout<<a<<f;} if (i==79){cout<<a<<g;} if (i==89){cout<<a<<h;} if (i==99){cout<<a<<j;} if ((i==100)&&(Wiederholung==0)){cout<<" "<<ei<<k;} if (i==200){cout<<" "<<zw<<k;} } //erste forschleife } //zweite forschleife } // ende der Funktion

#include <iostream> std::string strGetEinerName(char iZahl); std::string strGetZehnerName(char iZahl); int main() { std::string strdUnd = "und", strHundert = "hundert", strTausend = "tausend", strInputZahl; std::cout << "Geben Sie eine Zahl von 0 -1000 ein:\n"; std::cin >> strInputZahl; if (strInputZahl._Equal("1")) { std::cout << "eins\n"; } else if (strInputZahl._Equal("11")) { std::cout << "elf\n"; } else if (strInputZahl._Equal("12")) { std::cout << "zwoelf\n"; } else if (strInputZahl._Equal("16")) { std::cout << "sechzehn\n"; } else if (strInputZahl._Equal("1000")) { std::cout << "eintausend\n"; } else { if (strInputZahl.size() > 1 && strInputZahl.size() < 3) { std::cout << strGetEinerName(strInputZahl[1]) << strdUnd << strGetZehnerName(strInputZahl[0]) << "\n"; } else if (strInputZahl.size() > 2 && strInputZahl.size() < 4) { if (((int)strInputZahl[1] - 48) == 0 && ((int)strInputZahl[2] - 48) == 1) { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << "eins\n"; } else if (((int)strInputZahl[1] - 48) == 1 && ((int)strInputZahl[2] - 48) == 1) { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << "elf\n"; } else if (((int)strInputZahl[1] - 48) == 1 && ((int)strInputZahl[2] - 48) == 2) { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << "zwoelf\n"; } else if (((int)strInputZahl[1] - 48) == 1 && ((int)strInputZahl[2] - 48) == 6) { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << "sechzehn\n"; } else if (((int)strInputZahl[1] - 48) > 0) { if (((int)strInputZahl[2] - 48) > 0) { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << strGetEinerName(strInputZahl[2]) << strdUnd << strGetZehnerName(strInputZahl[1]) << "\n"; } else { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << strGetZehnerName(strInputZahl[1]) << "\n"; } } else { std::cout << strGetEinerName(strInputZahl[0])/*Geht auch für die Hunderter*/ << strHundert << strdUnd << strGetEinerName(strInputZahl[2]) << "\n"; } } else if (strInputZahl.size() == 1) { std::cout << strGetEinerName(strInputZahl[0]) << "\n"; } else { std::cout << "Diese Zahl wird nicht Supportet!\n"; } } system("pause"); return 0; } std::string strGetEinerName(char iZahl) { switch (iZahl) { case '1': return "ein"; break; case '2': return "zwei"; break; case '3': return "drei"; break; case '4': return "vier"; break; case '5': return "fuenf"; break; case '6': return "sechs"; break; case '7': return "sieben"; break; case '8': return "acht"; break; case '9': return "neun"; break; } } std::string strGetZehnerName(char iZahl) { switch (iZahl) { case '1': return "zehn"; break; case '2': return "zwanzig"; break; case '3': return "dreissig"; break; case '4': return "vierzig"; break; case '5': return "fuenfzig"; break; case '6': return "sechzig"; break; case '7': return "siebzig"; break; case '8': return "achzig"; break; case '9': return "neunzig"; break; } }