Termin 3 aufgabe

This commit is contained in:
Daniel Zwanzig 2025-04-11 10:57:58 +02:00
parent 32c381ed6a
commit fc9f52f533

73
v3.cpp Normal file
View File

@ -0,0 +1,73 @@
#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 == false);
cout << "Erste Zahl:";
cin >> ersteZahl;
cout << "Zweite Zahl:";
cin >> zweiteZahl;
switch (operation) {
case '+':
addition(ersteZahl, zweiteZahl);
case '-':
subtraktion(ersteZahl, zweiteZahl);
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);
}
}