Powershell Taschenrechner Programm Fehlerausgabe sonderzeichen?

Hallo Leute ich hab hier ein Skript für einen Taschenrechner und müsste hier nur die Funktion einbauen das er mir bei der Eingabe von Sonderzeichen eine ordentliche Fehlerausgabe gibt.
Dies hier ist soweit der Code:

Write-Host "Geben Sie zwei Zahlen ein" -ForegroundColor Red

Write-Host "Wählen Sie eine der vier möglichen Rechenoperationen aus:" -ForegroundColor Green

Write-Host "1: Zahl1 : Zahl2 = Ergebnis"

Write-Host "2: Zahl1 + Zahl2 = Ergebnis"

Write-Host "3: Zahl1 - Zahl2 = Ergebnis"

Write-Host "4: Zahl1 * Zahl2 = Ergebnis"

$Zahl1 = Read-Host "Bitte geben Sie die erste Zahl ein" 

$Zahl2 = Read-Host "Bitte geben Sie die zweite Zahl ein"

[int]$Eingabe = Read-Host "Wählen Sie eine Rechenoperation"

$Zahl1 = $Zahl1.Replace(",",".")

$Zahl2 = $Zahl2.Replace(",",".")

$Zahl1 = [double] $Zahl1

$Zahl2 = [double] $Zahl2

#Zulässige Rechenoperationen definiert

switch ($Eingabe) {

1 {$Ergebnis = $Zahl1 / $Zahl2}

2 {$Ergebnis = $Zahl1 + $Zahl2}

3 {$Ergebnis = $Zahl1 - $Zahl2}

4 {$Ergebnis = $Zahl1 * $Zahl2}

}

#Fehlerausgabe bei Division durch 0 und Programmabbruch

if(($Zahl2 -eq 0) -and ($Eingabe -eq 1)){

$antwort = "Es darf nicht durch 0 geteilt werden";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ungültige Eingabe"); break 

}

#Eingabe Rechenoperation darf nicht kleiner 1 und größer 4 sein.

if(($Eingabe -lt 1) -or ($Eingabe -gt 4) -or ($Eingabe -gt 10)){

$antwort = "Die Eingabe liegt nicht im Wertebereich 1-4";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ungültige Eingabe"); break

}

#stimmt die Eingabe mit dem Muster überein, so erfolgt die Berechnung und Ausgabe des Ergebnisses

else{

if($Eingabe -eq 1){

$antwort = "      <" + $Zahl1 + "> : <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A durch B");

   }

if($Eingabe -eq 2){

$antwort = "      <" + $Zahl1 + "> + <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A plus B");

if($Eingabe -eq 3){

$antwort = "      <" + $Zahl1 + "> - <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A minus B");

}

if($Eingabe -eq 4){

$antwort = "      <" + $Zahl1 + "> * <" + $Zahl2 + ">  =  <" + $Ergebnis + ">      ";

[System.Windows.Forms.MessageBox]::Show($antwort, "Ergebnis zu A mal B");

}

}

Kann mir da jemand weiterhelfen ohne meinen Code komplett zu verändern?

Computer, skript, Taschenrechner, PowerShell, Powershell ISE
Mit 820-870 Euro "Gaming-PC"-Setup möglich in WQHD bis 144Hz zu zocken?

Setup hier:

  • https://www.amazon.com/dp/B07STGGQ18?tag=pcpapi-20&linkCode=ogi&th=1&psc=1 Ryzen 5 3600
  • https://www.amazon.com/dp/B07XH4SK17?tag=pcpapi-20&linkCode=ogi&th=1&psc=1 B450M M2 Max
  • https://www.amazon.com/dp/B07MNJP6RW?tag=pcpapi-20&linkCode=ogi&th=1&psc=1 Crucial Ballistix Sport DDR4-3200MHz 16GB (2x8)
  • https://www.amazon.com/dp/B07J2WBKXF?tag=pcpapi-20&linkCode=ogi&th=1&psc=1 Crucial P1 500GB SSD (ist die schnell genug in Schreiben/Lesen?)
  • https://www.amazon.com/dp/B07WN6WB4G?tag=pcpapi-20&linkCode=ogi&th=1&psc=1 RTX 2070S Gaming OC
  • https://www.amazon.com/DEEPCOOL-MATREXX-30-Mini-Tower-Air-Intake/dp/B07QZDM8K4/ref=sr_1_7?crid=2BC9B55O3TMED&keywords=micro+atx+case&qid=1580052268&sprefix=micro+a%2Caps%2C264&sr=8-7 Deepcool Matrexx (falls zu schwache/wenige Lüfter, welche dann?)
  • https://www.amazon.com/EVGA-100-BR-0450-K1-Bronze-Power-Supply/dp/B07DTP6SLJ/ref=sr_1_2?crid=1QNZZQIIOBS5D&keywords=450w+power+supply&qid=1580052405&sprefix=450w+%2Caps%2C248&sr=8-2 450W 80+ Bronze Netzteil

Es ist auch kein Problem, nach Österreich (einzeln) zu liefern, weil alles gratis (hoffentlich) aus Amerika geliefert wird (kein Problem, dass ich 1 Woche warte).
Hier alles in Deutschland und Österreich ist vieles überteuert (z.B. der Ryzen kostet umgerechnet in Euro 162, in Österreich und Deutschland um die 200. Schreibt mal was ihr denkt! =)

PC, Computer, Technik, Gaming, AMD, WQHD, Spiele und Gaming, Ryzen , Nvidia GeForce RTX

Meistgelesene Beiträge zum Thema Computer