using System;
namespace Taschenrechner
{
public enum Operationen
{
Addition,
Subtraktion,
Multiplikation,
Division
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Taschenrechner v1.2\n");
Operationen operation = OperatorEingabe();
Console.WriteLine(operation + "\n");
int IntegerZahl1 = OperandEingabe("Ihre erste Zahl: ");
int IntegerZahl2 = OperandEingabe("Ihre zweite Zahl: ");
int Ergebnis = Berechne(operation, IntegerZahl1, IntegerZahl2);
Console.WriteLine("Das Ergebnis: " + Ergebnis);
Console.WriteLine("\n\nEnter, um zu beenden.");
Console.ReadKey();
}
static int Berechne(Operationen operation, int operandA, int operandB)
{
switch (operation)
{
case Operationen.Addition: return operandA + operandB;
case Operationen.Subtraktion: return operandA - operandB;
case Operationen.Multiplikation: return operandA * operandB;
case Operationen.Division: return operandA / operandB;
default: throw new NotImplementedException();
}
}
static int OperandEingabe(string text)
{
int input = 0;
do { Console.WriteLine("Ihre erste Zahl: "); }
while (!Int32.TryParse(Console.ReadLine(), out input));
return input;
}
static Operationen OperatorEingabe()
{
Console.WriteLine("Bitte wählen sie eine mathematische Operation:");
Console.WriteLine("---------------------------");
Console.WriteLine("Addition [1]");
Console.WriteLine("Subtraktion [2]");
Console.WriteLine("Multiplikation [3]");
Console.WriteLine("Division [4]");
Console.WriteLine("---------------------------");
int input = 0;
do
{
Console.WriteLine("Ihre Eingabe: ");
Int32.TryParse(Console.ReadLine(), out input);
} while (input <= 0 || input > 4);
return (Operationen)input - 1;
}
}
}