だから、私はC#言語全体にちょっと慣れていないので、誰かが単純なif elseをスイッチに変換するように頼んだ. これが私が知っているすべてです。それが正しいか?そうでない場合は、どこに問題があるか教えていただけますか? または何かが欠けていますか?ここでの唯一の問題は、スイッチ ケースの出力が表示されないことです。
static void Main(string[] args)
{
Console.Write("Enter Name: ");
string studname = Console.ReadLine();
Console.Write("Enter Age: ");
string age = Console.ReadLine();
Console.Write("Enter Year Level: ");
int level = int.Parse(Console.ReadLine());
Console.Write("Enter Course: ");
string course = Console.ReadLine();
Console.Write("Enter Score 1: ");
int num1 = int.Parse(Console.ReadLine());
Console.Write("Enter Score 2: ");
int num2 = int.Parse(Console.ReadLine());
Console.Write("Enter Score 3: ");
int num3 = int.Parse(Console.ReadLine());
int total = num1 + num2 + num3;
int ave = (num1 + num2 + num3) / 3;
int rate = ave;
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.Write("Student Name: " + studname);
Console.WriteLine("");
Console.Write("Student Age: " + age);
Console.WriteLine("");
Console.Write("Student Year Level: " + level);
Console.WriteLine("");
Console.Write("Student Course: " + course);
Console.WriteLine("");
Console.Write("Score 1: " + num1);
Console.WriteLine("");
Console.Write("Score 2: " + num2);
Console.WriteLine("");
Console.Write("Score 3: " + num3);
Console.WriteLine("");
Console.Write("Total_Score= " + total);
Console.WriteLine("");
Console.Write("Total_Average= " + ave);
switch (rate)
{
case 1:
if (rate < 100 && rate > 90)
Console.Write("Rate = 1.00");
Console.WriteLine("");
Console.Write("Hi! " + studname + "you Passed");
Console.WriteLine("");
break;
case 2:
if (rate < 89 && rate > 85)
Console.Write("Rate = 1.00");
Console.WriteLine("");
Console.Write("Hi! " + studname + "you Passed");
Console.WriteLine("");
break;
case 3:
if (rate < 84 && rate > 80)
Console.Write("Rate = 1.00");
Console.WriteLine("");
Console.Write("Hi! " + studname + "you Passed");
Console.WriteLine("");
break;
case 4:
if (rate < 79 && rate > 75)
Console.Write("Rate = 1.00");
Console.WriteLine("");
Console.Write("Hi! " + studname + "you Passed");
Console.WriteLine("");
break;
case 5:
if (rate < 75)
Console.Write("Rate = 5.00");
Console.WriteLine("");
Console.Write("Hi! " + studname + "you Failed");
Console.WriteLine("");
break;
}
Console.ReadLine();
}