OPR_Pr/v3.cpp
2025-04-11 11:01:50 +02:00

74 lines
2.0 KiB
C++

#include <iostream>
#define EOF (-1)
using namespace std;
double addition(double ersteZahl, double zweiteZahl){
double erg = ersteZahl + zweiteZahl;
cout << ersteZahl<< " + " << zweiteZahl << " = " << erg << endl;
return erg;
}
double subtraktion(double ersteZahl, double zweiteZahl){
int erg = ersteZahl - zweiteZahl;
cout << ersteZahl<< " - " << zweiteZahl << " = " <<erg << endl;
return erg;
}
double multiplikation(double ersteZahl,double zweiteZahl){
double erg = ersteZahl * zweiteZahl;
cout << ersteZahl<< " * " << zweiteZahl << " = " <<erg << endl;
return erg;
}
double division(double ersteZahl, double zweiteZahl){
double erg = ersteZahl / zweiteZahl;
cout << ersteZahl<< " : " << zweiteZahl << " = " << erg << endl;
return erg;
}
int main() {
char operation, clear;
int ersteZahl, zweiteZahl;
bool pruef = false;
do {
cout << "Welche Rechenoperation wollen Sie durchfuehren? [ + | - | / | * ]:";
cin >> operation;
if (operation == '+')
{
pruef = true;
} else if (operation == '*') {
pruef = true;
} else if (operation == '/') {
pruef = true;
} else if (operation == '-') {
pruef = true;
} else {
cout << "Keine definierte Rechenoperation!" << endl;
while ((clear = getchar()) != '\n' && clear != EOF) { }
}
} while (!pruef);
cout << "Erste Zahl:";
cin >> ersteZahl;
cout << "Zweite Zahl:";
cin >> zweiteZahl;
switch (operation) {
case '+':
addition(ersteZahl, zweiteZahl);
case '-':
subtraktion(ersteZahl, zweiteZahl);
break;
case '*':
multiplikation(ersteZahl, zweiteZahl);
case '/':
while (zweiteZahl == 0){
cout << "Man kann nicht durch 0 teilen. Geben Sie eine neue zweite Zahl ein:";
cin >> zweiteZahl;
}
division(ersteZahl, zweiteZahl);
}
}