From a6818c0e834aac82ca27601e36089e7e9bde6676 Mon Sep 17 00:00:00 2001 From: hannesa7x Date: Wed, 15 Apr 2020 12:27:15 +0200 Subject: [PATCH] =?UTF-8?q?Programm=20wurde=20um=20die=20Funktionalit?= =?UTF-8?q?=C3=A4t=20von=20Modulo=20erweitert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Taschenrechner/ConsoleView.cs | 10 +++++++--- Taschenrechner/RechnerModel.cs | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Taschenrechner/ConsoleView.cs b/Taschenrechner/ConsoleView.cs index af5ead5..5c88e55 100644 --- a/Taschenrechner/ConsoleView.cs +++ b/Taschenrechner/ConsoleView.cs @@ -54,8 +54,8 @@ public void HoleEingabenFuerFortlaufendeBerechnung() } else { - model.ErsteZahl = model.Resultat; - model.ZweiteZahl = Convert.ToDouble(eingabe); + model.ErsteZahl = Convert.ToDouble(HoleZahlVomBenutzer()); + model.ZweiteZahl = model.Resultat; } } @@ -94,7 +94,7 @@ private string HoleOperatorVomBenutzer() do { - Console.Write("Bitte gib die auszuführende Operation ein (+, -, /, *): "); + Console.Write("Bitte gib die auszuführende Operation ein (+, -, /, *, m): "); operation = Console.ReadLine(); model.Operation = operation; @@ -128,6 +128,10 @@ public void GibResultatAus() Console.WriteLine("Das Produkt ist: {0}", model.Resultat); break; + case "m": + Console.WriteLine("Der Rest von Zahl1 nach Division durch Zahl2 ist: {0}", model.Resultat); + break; + default: Console.WriteLine("Du hast eine ungültige Auswahl der Operation getroffen."); break; diff --git a/Taschenrechner/RechnerModel.cs b/Taschenrechner/RechnerModel.cs index 606e186..ca9b0b2 100644 --- a/Taschenrechner/RechnerModel.cs +++ b/Taschenrechner/RechnerModel.cs @@ -71,6 +71,7 @@ public string Operation case "-": case "/": case "*": + case "m": // Es wurde eine gültige Operation übergeben. Daher können wir // den Fehler zurücksetzen ... if (AktuellerFehler == Fehler.UngueltigeOperation) @@ -121,6 +122,10 @@ public void Berechne() Resultat = Multipliziere(ErsteZahl, ZweiteZahl); break; + case "m": + Resultat = Modulo((int)ErsteZahl, (int)ZweiteZahl); + break; + default: AktuellerFehler = Fehler.UngueltigeOperation; break; @@ -167,5 +172,10 @@ private double Multipliziere(double multiplikator, double multiplikand) { return multiplikator * multiplikand; } + + private int Modulo(int dividend, int divisor) + { + return dividend % divisor; + } } }