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
Quellcode |
|
1 |
error C2181: Ungueltiges 'else' ohne zugehoeriges 'if' |
C-/C++-Quelltext |
|
1 2 |
else if (nWahl == 3) cout << "Programm wird beendet...\n\n\n"; |
C-/C++-Quelltext |
|
1 2 3 |
else if (nWahl == 2) cout << "\n\n\n\n\nProgramm\n"; cout << "\fIn Arbeit!"; |
C-/C++-Quelltext |
|
1 2 3 4 |
while (nWahl != 3) { ... } |
Quellcode |
|
1 2 3 4 5 |
if(..) { ... } else if(...) { ... } |
C-/C++-Quelltext |
|
1 2 3 4 |
else if (nWahl == 2) cout << "\n\n\n\n\nProgramm\n"; // Hier ist das Ende der If-Anweisung! Das zweite cout wird immer ausgeführt. Richtig wäre. beides in { } cout << "\fIn Arbeit!"; |
C-/C++-Quelltext |
|
1 2 3 4 |
if(nWahl == 1) [do something] else if (nWahl == 3) cout << "Programm wird beendet...\n\n\n"; |
C-/C++-Quelltext |
|
1 2 3 4 5 |
if(blubb) std::cout << "Blubb"; std::cout<<"Kein If mehr"; else if(bla) std::cout<<"bla"; |
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 |
//BMI-Check //Programm zum Berechnen des BMI's // //1: BMI berechnen // void funcBerechnen (float fGewicht, float fGroesse, float fBMI); { cout << "\n\n\n\n\nBMI-Check 1.0\n"; cout << "_____________________________________________________________________________\n\n"; cout << "\tIn Arbeit!"; } //Hauptprogramm // int main () { //Variablen // int nWahl; float fBMI; float fGewicht; float fGroesse; //Menue-Schleife // while (nWahl != 3) { cout << "\n\n\n\n\nBMI-Check 1.0\n"; cout << "_____________________________________________________________________________\n\n"; cout << "\t1: BMI berechnen"; cout << "\t2: Info"; cout << "\t3: Programm beenden"; cout << "\tIhre Wahl: "; cin >> nWahl; //1: Berechnen? // if (nWahl == 1) { funcBerechnen (fGewicht, fGroesse, fBMI); } //2: Info? // else if (nWahl == 2) { cout << "\n\n\n\n\nBMI-Check 1.0\n"; cout << "_____________________________________________________________________________\n\n"; cout << "\tIn Arbeit!"; } else if (nWahl == 3) { cout << "\n\n\tProgramm wird beendet..."; } else { cout << "\n\n\tFalsche Eingabe!"; } } return 0; } |
Zitat von »"Helmut"«
Ich bin aber mal froh, dass endlich mal ein Anfänger das if gleich als if-Bedingung bezeichnet, und nicht if-Schleife
Werbeanzeige