CBruns
New member
- Joined
- Sep 2, 2020
- Messages
- 3
- Programming Experience
- Beginner
It worked 1 Hour ago and yet when i am home it doesnt work anymore
It should throw an exception whenever someone typed in 0 so that he can renew it now it divides by i dont know what and the same anwser is 8 all the time when i want to divide by zero
It should throw an exception whenever someone typed in 0 so that he can renew it now it divides by i dont know what and the same anwser is 8 all the time when i want to divide by zero
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace exception2
{
class Program
{
private const string Value = "Sie haben versucht mit null zu dividieren die zahl wird jetzt automatisch auf 1 gesetzt";
static void Main(string[] args)
{
double zahl1 = 0;
double zahl2 = 0;
double zahl3 = 0;
Console.WriteLine("Bitte geben sie eine Zahl ein");
zahl1 = Convert.ToDouble(Console.ReadLine());
try
{
Console.WriteLine("Bitte geben sie eine Zweite Zahl ein die nicht NULL oder 0 ist");
zahl2 = Convert.ToDouble(Console.ReadLine());
}
catch (Exception l)
{
Console.WriteLine(l.Message);
Console.WriteLine(Value);
zahl2 = 1;
Console.ReadKey();
}
try
{
zahl3 = zahl1 / zahl2;
}
catch (DivideByZeroException)
{
Console.WriteLine("Bitte geben sie eine zahl ein die NICHT 0 ist");
zahl2 = Convert.ToDouble(Console.ReadLine());
if (zahl2 == 0)
{
Console.WriteLine("Ich habe gesagt NICHT durch NULL 0 du Vollidiot");
Console.WriteLine("Das Programm wird sich jetzt selber schließen");
Console.ReadKey();
Environment.Exit(0);
}
if (zahl2 != 0)
{
}
}
Console.WriteLine("Der Quotient ist" + " " + zahl3);
Console.ReadKey();
}
}
}
Last edited by a moderator: