Ошибка в коде - C# (179046)
Формулировка задачи:
Недавно начал изучать c#, столкнулся с проблемой.
Ошибка компиляции
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Calc();
Console.ReadKey();
}
public static void Calc()
{
Console.WriteLine("Введите первое число.");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите второе число.");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Выберете действие: 1 - сложение, 2 - вычитание, 3 - умножение, 4 - деление.");
int c = Convert.ToInt32(Console.ReadLine());
int d;
if (c == 1) d = a + b;
if (c == 2) d = a - b;
if (c == 3) d = a * b;
if (c == 4) d = a / b;
Console.WriteLine(d);
}
}
}Решение задачи: «Ошибка в коде»
textual
Листинг программы
if (c == 1) d = a + b;
else if (c == 2) d = a - b;
else if (c == 3) d = a * b;
else if (c == 4) d = a / b;
else
{
Console.WriteLine("Ошибка!");
return;
}
Console.WriteLine(d);