Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
#include <iostream> using namespace std; void addition(float x, float y); void subtraktion(float x, float y); void multiplikation(float x, float y); void division(float x, float y); int main (void) { cout << "Druecke A fuer Addition, S fuer Subtraktion, M fuer Multiplikation und D fuer Division. Zum Beenden druecke E." << endl; float x,y; char wahl; cin >> wahl; switch( wahl ) { case 'a': case 'A': cout << addition(x,y) break; case 's': case 'S': cout << subtraktion(); break; case 'm': case 'M': cout << multiplikation(); break; case 'd': case 'D': cout << division(); break; case 'e': case 'E': return 0; default: cout << "Ungueltige Eingabe. Das Programm wird beendet"; cin.sync(); cin.get(); return 0; } cout << "" << endl; return main(); } void addition(); { float x,y; cout << "Zahl 1 eingeben: "; cin >> x; cout << "Zahl 2 eingeben: "; cin >> y; return x+y; } void subtraktion(float x, float y); { float x, y; cout << "Zahl 1 eingeben: "; cin >> x; cout << "Zahl 2 eingeben: "; cin >> y; return x - y; } void multiplikation(float x, float y); { float x, y; cout << "Zahl 1 eingeben: "; cin >> x; cout << "Zahl 2 eingeben: "; cin >> y; return x * y; } void division(float x, float y); { float x, y; cout << "Zahl 1 eingeben: "; cin >> x; cout << "Zahl 2 eingeben: "; cin >> y; return x / y; } |
Administrator
C-/C++-Quelltext |
|
1 |
cout << "" << endl; |
C-/C++-Quelltext |
|
1 |
cout << endl; |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# include <iostream> using namespace std; int addition(int a1, int a2){ return a1+a2; } int subtraktion(int s1, int s2){ return s1-s2; } int multiplikation(int m1, int m2){ return m1*m2; } int division(int d1, int d2){ return d1/d2; } int main (){ int a1,a2,s1,s2,m1,m2,d1,d2,auswahl; cout << "Waehle die gewuenschte Rechenart." << endl; Anfang: cout << "1 - Addition" << endl; cout << "2 - Subtraktion" << endl; cout << "3 - Multiplikation" << endl; cout << "4 - Division" << endl; cout << "5 - Beenden" << endl; cout << endl; cin >> auswahl; while(auswahl > 0 && auswahl <=4){ switch(auswahl){ case 1: cout << endl; cout << "Du moechtest also addieren." << endl; cout << "Bitte gib Zahl 1 ein: "; cin >> a1; cout << "Und nun Zahl 2: "; cin >> a2; cout << "Das Ergebnis lautet: " << addition(a1,a2) << endl; cout << endl; cout << "Wie moechtest Du weitermachen? Triff eine Auswahl!" << endl; goto Anfang; break; case 2: cout << endl; cout << "Du moechtest also subtrahieren." << endl; cout << "Bitte gib Zahl 1 ein: "; cin >> s1; cout << "Und nun Zahl 2: "; cin >> s2; cout << "Das Ergebnis lautet: " << subtraktion(s1,s2) << endl; cout << endl; cout << "Wie moechtest Du weitermachen? Triff eine Auswahl!" << endl; goto Anfang; break; case 3: cout << endl; cout << "Du moechtest also multiplizieren." << endl; cout << "Bitte gib Zahl 1 ein: "; cin >> m1; cout << "Und nun Zahl 2: "; cin >> m2; cout << "Das Ergebnis lautet: " << multiplikation(m1,m2) << endl; cout << endl; cout << "Wie moechtest Du weitermachen? Triff eine Auswahl!" << endl; goto Anfang; cin >> auswahl; break; case 4: cout << endl; cout << "Du moechtest also dividieren." << endl; cout << "Bitte gib Zahl 1 ein: "; cin >> d1; cout << "Und nun Zahl 2: "; cin >> d2; cout << "Das Ergebnis lautet: " << division(d1,d2) << endl; cout << endl; cout << "Wie moechtest Du weitermachen? Triff eine Auswahl!" << endl; goto Anfang; break; } } if (auswahl == 5){ cout << endl; cout << "Das Programm wird beendet...." << endl; } else{ cout << endl; cout << "Du solltest dir doch eine Zahl zwischen 1 und 5 aussuchen und nicht " << auswahl << "!" << endl; cout << "Wie moechtest Du weitermachen? Triff eine Auswahl." << endl; goto Anfang; } cin.sync(); cin.get(); return 0; } |
Es gibt nur SEEEEEHR selten (bis gar nicht) wirkliche Situationen, in denen ein goto sinnvoll ist.
Werbeanzeige