// aufgabe_6.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#include
using namespace std;
int addieren(int a, int b);
int subtrahieren(int a, int b);
int multiplizieren(int a, int b);
int dividieren(int a, int b);
double addieren(double a, double b);
double subtrahieren(double a, double b);
double multiplizieren(double a, double b);
double dividieren(double a, double b);
int main()
{
char c,d;
int a,b=0;
double e, f=0, summe;
do
{
do
{
cout << "Minirechner: (i)nteger oder (d)ouble ? ";
cin >> d;
}while(d != 'i' && d != 'd');
cout << "Zahl 1 = ? ";
if(d == 'i')
cin >> a;
else
cin >> e;
do
{
cout << "Rechenart (+ - * /) ? ";
cin >> c;
} while (c != 43 && c != 45 && c != 42 && c != 47);
if(d == 'i')
{
do
{
cout << "Zahl 2 = ? ";
cin >> b;
}while(c == 47 && b == 0);
switch(c)
{
case '+':
summe = addieren(a,b);
break;
case '-':
summe = subtrahieren(a,b);
break;
case '*':
summe = multiplizieren(a,b);
break;
case '/':
summe = dividieren(a,b);
break;
}
cout << a << c << b << "=" << summe;
}
else
{
do
{
cout << "Zahl 2 = ? ";
cin >> f;
}while(c == '/' && f == 0);
switch(c)
{
case '+':
summe = addieren(e,f);
break;
case '-':
summe = subtrahieren(e,f);
break;
case '*':
summe = multiplizieren(e,f);
break;
case '/':
summe = dividieren(e,f);
break;
}
cout << e << c << f << "=" << summe;
}
cout << "\n\nNoch einmal (j/n)? ";
cin >> c;
}
while(c=='j');
return 0;
}
int addieren(int a, int b)
{
return a + b;
}
int subtrahieren(int a, int b)
{
return a - b;
}
int multiplizieren(int a, int b)
{
return a * b;
}
int dividieren(int a, int b)
{
if(b)
return a / b;
return 0;
}
double addieren(double a, double b)
{
return a + b;
}
double subtrahieren(double a, double b)
{
return a - b;
}
double multiplizieren(double a, double b)
{
return a * b;
}
double dividieren(double a, double b)
{
if(b)
return a / b;
return 0;
}