大家好,我是 C# 新手,目前正处于试验 if-else 语句的阶段。在声明变量ageUser、allowedAge、input并运行程序后,我注意到 if 语句和结果输出似乎不匹配。
int ageUser;
int permittedAge = 18;
int input;
Console.Write("Put in your age: ");
input = Convert.ToInt32(Console.Read());
ageUser = input;
if (ageUser < permittedAge)
{
Console.WriteLine("Sorry you are not permitted to enter this site!");
}
else
{
Console.WriteLine("Welcome");
}