i believe i solved the issue by by giving number1
and number2
a value of 0
im just starting out with coding and am trying to make a simple calculator. ive placed my string to int parse in a try block but now the rest of the app can not see the variables number1 or number2, how do i make it so that the rest of the app can see these variables?
int number1;
int number2;
try
{
bool test1 = int.TryParse(input1, out number1);
bool test2 = int.TryParse(input2, out number2);
if (!test1)
{
throw new Exception("Convertion failed");
}
}
catch (Exception ex)
{
Console.WriteLine("there was an error", ex.Message);
}
if (operation == add1 || operation == add2)
{
int answer = number1 + number2;
Console.WriteLine("the answer is " + answer);
return;
}