Not counting right?
本文关键字:right counting Not | 更新日期: 2023-09-27 17:50:19
我试图让这个计数和收集信息为不同的变量使用一个开关语句,但它只能计数到4。
我知道我可以用数组更容易地做到这一点。
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class WeekThreeLab
{
static void Main()
{
String name, city;
Double Drating;
Double Judge1;
Double Judge2;
Double Judge3;
Double Judge4;
Double Judge5;
Judge1 = 0;
Judge2 = 0;
Judge3 = 0;
Judge4 = 0;
Judge5 = 0;
System.Console.Write("What is the drivers name: ");
name = System.Console.ReadLine();
System.Console.Write("What is the drivers city: ");
city = System.Console.ReadLine();
System.Console.Write("What is the degree of difficulty: ");
Drating = Double.Parse(System.Console.ReadLine());
while (Drating <= 0.99 || Drating >= 1.68)
{
Console.Write("Invalid! Try again! Degree of difficulty: ");
Drating = Double.Parse(System.Console.ReadLine());
}
for (int count = 0; count <= 4; count++)
{
switch (count)
{
case 1:
System.Console.Write("Judge #{0} and his score? ", count);
Judge1 = Double.Parse(System.Console.ReadLine());
while (Judge1 < 0 || Judge1 > 10)
{
System.Console.Write("Invalid range! Reenter, Judge #{0}: ", count);
Judge1 = Double.Parse(System.Console.ReadLine());
}
break;
case 2:
System.Console.Write("Judge #{0} and his score? ", count);
Judge2 = Double.Parse(System.Console.ReadLine());
while (Judge2 < 0 || Judge2 > 10)
{
System.Console.Write("Invalid range! Reenter, Judge #{0}: ", count);
Judge2 = Double.Parse(System.Console.ReadLine());
}
break;
case 3:
System.Console.Write("Judge #{0} and his score? ", count);
Judge3 = Double.Parse(System.Console.ReadLine());
while (Judge3 < 0 || Judge3 > 10)
{
System.Console.Write("Invalid range! Reenter, Judge #{0}: ", count);
Judge2 = Double.Parse(System.Console.ReadLine());
}
break;
case 4:
System.Console.Write("Judge #{0} and his score? ", count);
Judge4 = Double.Parse(System.Console.ReadLine());
while (Judge4 < 0 || Judge4 > 10)
{
System.Console.Write("Invalid range! Reenter, Judge #{0}: ", count);
Judge4 = Double.Parse(System.Console.ReadLine());
}
break;
case 5:
System.Console.Write("Judge #{0} and his score? ", count);
Judge1 = Double.Parse(System.Console.ReadLine());
while (Judge5 < 0 || Judge5 > 10)
{
System.Console.Write("Invalid range! Reenter, Judge #{0}: ", count);
Judge5 = Double.Parse(System.Console.ReadLine());
}
break;
}
}
System.Console.WriteLine(Judge1);
System.Console.WriteLine(Judge2);
System.Console.WriteLine(Judge3);
System.Console.WriteLine(Judge4);
System.Console.WriteLine(Judge5);
System.Console.WriteLine(" ");
System.Console.WriteLine("Your diver: {0} ");
System.Console.WriteLine("From the city: {0} ");
System.Console.WriteLine("Had a final score of: {0} ");
System.Console.ReadKey();
}
}
循环计数从0到4,但switch
检查值1到5。要包含所有5个裁判,将for循环更改为:
for (int count = 1; count <= 5; count++)
改变为
this => for (int count = 0; count <= 5; count++){..}
,在第五种情况下,您正在设置judge1变量:
Judge1 = Double.Parse(System.Console.ReadLine());
改为
Judge5 = Double.Parse(System.Console.ReadLine());