Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo Zusammen,

ich muss mich hier ein wenig mit c++ auseinander setzen und ich würde mal behaupten zu wissen, wie eine einfache if / else Abfrage aufgebaut ist aber irgendwie habe bei c++ mit dem else. Es wird komischerweise "immer" ausgeführt und das ist ja nicht der Sinn der Sache.


  void Entladen(){


	cout << "alle fertig? [0/1]" << endl;

	cin >> option1;


	if(option1 == 1){

	    cout << "eins" << endl;

	};

	if(option1 == 0){

	    cout << "null" << endl;

	    Entladen();

	};

	if(option1 != 0 && option1 != 1){

	    cout << "ausweich else" << endl;

	    Entladen();

	}

	else{

	    cout << "asd" << endl;

	}

    };


nicht wundern.. ich habe beim if(option1 != 0 && option1 != 1) mir nur eine else abfrage sozusagen erzeugt um das ganze zu testen. Dennoch wird überall das else (also "asd") mit ausgegeben.

Bearbeitet von dempsey

  • Autor

soll das mit anderen Worten heissen, ich sollte das else in der form weglassen?! ich habs früher mit auf den weg bekommen, dass ich immer ein else drinne haben soll wenn ich eine if abfrage mache

soll das mit anderen Worten heissen, ich sollte das else in der form weglassen?!
Nein, es soll heißen, dass das else das Ergebnis der ersten beiden if-Anweisungen ignoriert.

Außerdem brauchst du nicht 4 Zweige, wenn du nur 3 Fälle hast.

  void Entladen(){

cout << "alle fertig? [0/1]" << endl;
cin >> option1;

if(option1 == 1){
cout << "eins" << endl;
}
else if(option1 == 0){
cout << "null" << endl;
Entladen();
}
else {
cout << "ausweich else" << endl;
Entladen();
}
}[/code]

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.