If Elseステートメントを切り替えようとしていますが、定数が必要であるというエラーが表示されます。
これが私が取り組んできたコードです:
using System;
namespace ConsoleApplication6
{
class Program
{
static void Main()
{
String me;
int ME = 0, YOU = 5, THEY = 20, THEM = 30;
Console.WriteLine("Default Values: YOU = 5, THEY = 20 and THEM = 30\nValue for \"ME\" >>");
me = Console.ReadLine();
ME = Int16.Parse(me);
switch(true) {
case (ME > 0 && ME < 12) :
YOU = ME;
Console.WriteLine("Value of YOU is {0}", YOU);
break;
case ( ME == 15):
YOU = THEY * THEM;
Console.WriteLine("Value of YOU is {0}", YOU);
break;
case (ME == 20):
YOU++;
Console.WriteLine("Value of YOU is {0}", YOU);
break;
case (ME == 17):
YOU = YOU - 4;
Console.WriteLine("Value of YOU is {0}", YOU);
break;
default:
Console.WriteLine("You've entered {0}", ME);
Console.WriteLine("Value of YOU is {0}", YOU);
break;
}
Console.WriteLine("Press Enter to EXIT");
Console.ReadLine();
}
}
}
これが私が変換しようとしているものです:
using System;
namespace ConsoleApplication5
{
class Program
{
static void Main()
{
String me;
int ME = 0, YOU = 5, THEY = 20, THEM = 30;
Console.WriteLine("Default Values: YOU = 5, THEY = 20 and THEM = 30\nValue for \"ME\" >>");
me = Console.ReadLine();
ME = Int16.Parse(me);
if (0 < ME && ME < 12)
{
YOU = ME;
Console.WriteLine("Value of YOU is {0}", YOU);
}
else if( ME == 15)
{
YOU = THEY * THEM;
Console.WriteLine("Value of YOU is {0}", YOU);
}
else if (ME == 20)
{
YOU++;
Console.WriteLine("Value of YOU is {0}", YOU);
}
else if (ME == 17)
{
YOU = YOU - 4;
Console.WriteLine("Value of YOU is {0}", YOU);
}
else
{
Console.WriteLine("You've entered {0}", ME);
Console.WriteLine("Value of YOU is {0}", YOU);
}
Console.WriteLine("Press Enter to EXIT");
Console.ReadLine();
}
}
}