cplusplus-training/Teil_1/4. Kontrollstrukturen/Uebung 4 - Taschenrechner.cpp
2021-10-15 08:36:02 +02:00

35 lines
678 B
C++

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
float z1 = 0, z2 = 0;
char op = 0;
cout << "Bitte Ausdruck eingeben: \n";
cin >> z1 >> op >> z2;
switch (op)
{
case '+':
cout<< "Ergebnis: "<<(z1+z2)<<endl;
break;
case '-':
cout<< "Ergebnis: "<<(z1-z2)<<endl;
break;
case '*':
cout<< "Ergebnis: "<<(z1*z2)<<endl;
break;
case '/':
if(z2==0)
cout << "Division durch null!\n";
else
cout<< "Ergebnis: "<<(z1/z2)<<endl;
break;
default:
cout << "Es gab einen Fehler in der Anweisung";
}
}