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 ich möchte einen kleinen Taschrechner programmieren, wollte erstmal nur zwei Rechenarten einbinden. Ich kann die entsprechenden Eingaben machen, aber das Fenster schließt sich wieder ohne ein Ergebnis anzuzeugen.

Vielleicht wist ihr weiter, hier der Quelltext:

/*#######################################

Taschenrechner

######################################*/

#include <iostream.h>

int addition(int x, int y){

return (x+y);

}

int subtraktion(int x, int y){

return (x-y);

}

void main() {

int a;

int b;

int c;

cout<<"Zahl 1:";cin>>a;

cout<<"Zahl 2:"; cin>>b;

cout<<"Opperator:"; cin>>c;

if (c=='+')

cout<<"Ergebnis:"<<addition(a,B)<<endl;

else

cout<<"Ergebnis:"<<subtraktion(a,B)<<endl;

char p[50];

cin.getline(p,50);

cin.getline(p,50);

}

Danke schonmal im Voraus

Du könntest folgendes an Stelle der getline-Aufrufe an dein Programm anhängen:

cin.clear ();
cin.ignore(cin.rdbuf()->in_avail());
cin.get ();
[/code]

Nachtrag: c darf nicht int sein. char wäre richtig.

Nur als Anmerkung: Du solltest <iostream> statt <iostream.h> verwenden. Beachte aber, dass dann alle Standardfunktionen und -objekte im Namespace std liegen.

Danke für die Mühe, funktioniert leider immer noch nicht. Die Aufgabe kommt aus einem ILS-Lehrgang Thema Funktionen, Schleifen, If-Else was du mir geschickt hast hatten wir noch nicht.

Muss also auch irgendwie anders gehen.

du musst ja jede eingabe mit "Enter" bestätigen. Nach der Eingabe des Operators(3.Eingabe) und drücken der Entertaste schließt sich das Fenster.

Ich hoffe jetzt ist es präzise genug.

Ändere mal bitte wie von Klotzkopp gesagt int c in char c

Danke nochmal für Eure Hilfe, ich habe das Prob jetzt über eine switch-case Anweisung gelöst.

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.