Я пытаюсь сделать простой калькулятор, и я получаю эту ошибку "Использование неназначенной переменной 'операция'
выдает только ошибку при запуске оператора в одной строке
здесь: if ( операция == "x")
вся вещь:
static void Main()
{
int firstNumber;
int secondNumber;
string operation;
int answer;
Console.WriteLine("Hello welcome to Eral's Calculator");
Console.ReadLine();
Console.Write("Enter the first number for the equation");
firstNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number for the equation");
secondNumber = Convert.ToInt32(Console.ReadLine());
if (operation == "x")
{
answer = firstNumber * secondNumber;
Console.WriteLine(firstNumber + "x" + secondNumber + " = " + answer);
Console.ReadLine();
}
else if (operation == "+")
{
answer = firstNumber + secondNumber;
Console.WriteLine(firstNumber + "+" + secondNumber + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNumber - secondNumber;
Console.WriteLine(firstNumber + "-" + secondNumber + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNumber / secondNumber;
Console.WriteLine(firstNumber + "/" + secondNumber + "=" + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("That is not how you calculate, Try Again?");
Console.ReadLine();
}
}