using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace school_project_final
{
class Program
{
static void Main()
{
Console.WriteLine("who are you...?");
string name = Console.ReadLine();
Console.WriteLine("how old are you " + name + "?");
int age;
try
{
age = Convert.ToInt32(Console.ReadLine());
}
catch (FormatException)
{
Console.WriteLine("that's... not a number");
return;
}
finally
{
if (System.Convert.ToInt32(age) >= 18)
{
Console.WriteLine("so you're " + age + " years old, good to know");
}
else if (System.Convert.ToInt32(age) < 18 && System.Convert.ToInt32(age) > 0)
{
Console.WriteLine("so you're a child, how worthless");
}
Console.ReadLine();
}
}
}
}
if (System.Convert.ToInt32(age) >= 18)
This line returns an error that the age variable does not exist, but the other lines after it like
Console.WriteLine("so you're " + age + " years old, good to know");
and
else if (System.Convert.ToInt32(age) < 18 &&
System.Convert.ToInt32(age) > 0)
do not return this error, how do I fix this?