Termin 3 aufgabe
This commit is contained in:
parent
32c381ed6a
commit
fc9f52f533
73
v3.cpp
Normal file
73
v3.cpp
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user