fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct konto
  5. {
  6. std::string name;
  7. unsigned kontonummer;
  8. float kontostand;//Man könnte auch ein int nehmen, und in Cent rechnen
  9.  
  10. konto():
  11. name("Unbekannt")//Konstruktor für name wird aufgerufen;
  12. {
  13. kontonummer = 0;
  14. kontostand = 0; //Kein Startguthaben ;)
  15. }
  16. };
  17.  
  18. int main()
  19. {
  20. using std::cout;//Kannst in diesem Beispiel auch ganz normal using namespace std; verwenden,
  21. using std::cin;//einige sagen aber, man soll einzelne Bezeichner (Namen für variablen,Funktionen,Klassen) einzeln inmportieren um namenskonflikte zu vermeiden.
  22.  
  23. konto Konto;
  24.  
  25. cout << "Herzlich Willkommen bei dem Kontoverwalter !\n\n"
  26. "Ihr Name: ";
  27. std::getline(cin, Konto.name);
  28.  
  29. cout << "\nWunschkontonummer: ";
  30. cin >> Konto.kontonummer;
  31.  
  32. cout << "\nWieviel wollen sie einlegen? (max. 20000, min 1): ";
  33. cin >> Konto.kontostand;
  34.  
  35. while(Konto.kontostand > 20000.00 || Konto.kontostand <= 0)
  36. {
  37. cout << "Die Summe liegt außerhalb des g\201ltigen Wertebereichs. Bitte geben Sie eine neue Summe ein: " ;
  38. cin >> Konto.kontostand;
  39. }
  40.  
  41. cout << "\nKonto ("<< Konto.kontonummer <<") wurde mit "<< Konto.kontostand <<" Euro auf den Namen "<< Konto.name << " erstellt !\n";
  42.  
  43. cin.ignore();
  44. cin.get();//Guck dir solche Sachen umbedingt nochmal an, das ist jetzt nur flüchtig eine Lösung
  45. }
Success #stdin #stdout 0s 2864KB
stdin
Max Mustermann
123456789
1500
stdout
Herzlich Willkommen bei dem Kontoverwalter !

Ihr Name: 
Wunschkontonummer: 
Wieviel wollen sie einlegen? (max. 20000, min 1): 
Konto (123456789) wurde mit 1500 Euro auf den Namen Max Mustermann erstellt !