Деление на ноль - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConApp
{
class Program
{
static void Main(string[] args)
{
int operand1 = 10, operand2 = 0;
int result = 0;
Console.WriteLine("Пользователь введите одну из 4 арифметический операций: / * + - ");
String sign = Console.ReadLine();
switch (sign)
{
case "/":
Console.WriteLine(result = operand1 / operand2);
break;
case "*":
Console.WriteLine(operand1 * operand2);
break;
case "+":
Console.WriteLine(operand1 + operand2);
break;
case "-":
Console.WriteLine(operand1 - operand2);
break;
default:
Console.WriteLine("Попробуйте еще раз!");
break;
}
if (result == 0)
{
Console.WriteLine("делить на ноль нельзя");
}
Console.ReadKey();
}
}
}Решение задачи: «Деление на ноль»
textual
Листинг программы
case "/":
{
if (operand2 == 0)
Console.WriteLine("На ноль делить нельзя");
else
Console.WriteLine(result = operand1 / operand2);
break;
}