现在工作! 在阅读了所有人不得不说的内容后,我开始玩它并从网站上阅读提示。
*对于将来阅读的人。我错过了下面的答案中提到的一些括号,我补充说。我也犯了不检查if语句的错误。我有以下情况,状态必须等于“AL”等等。这是不可能的,因为那些是分裂。
感谢任何可以提供帮助的人,格式化是我的一个弱点。所有这些代码需要做的是显示AL和NL分区中的团队的数组中的所有信息,以及两个不是数组格式的列。一个是显示(赢/总)的变量,另一个列显示(运行得分和反对)之间的差异。
但是,我一直收到输入字符串错误的错误。我对确切的错误有些不确定。
我的第一个猜测是,或许,因为我没有数组格式的最后两列导致错误。但是,我不确定我是否可以把它们放在一个空数组中。
或者,也许是因为当我调用这两个模块时,我重复了两个数组名称。我做到了这一点,因为我看到我的老师在他在课堂上向我们展示的一个例子中做了这件事。但是,这次似乎没有用。
我试图在没有文字轰炸的情况下提供尽可能多的信息,如果需要,我可以提供任何其他信息。
活泉!感谢信息,错误消失了!可悲的是,我似乎无法从数组中获取任何信息以显示在列中。
string[] teams = { "Boston Red Sox", "New York Yankees", "Tampa Bay Rays", "Toronto Blue Jays", "Baltimore Orioles",
"Cleveland Indians", "Minnesota Twins", "Kansas City Royals", "Chicago White Sox", "Detroit Tigers", "Houston Astros", "Los Angeles Angels",
"Seattle Mariners", "Texas Rangers", "Oakland Athletics", "Washington Nationals", "Miami Marlins", "Atlanta Braves", "New York Mets", "Philadelphia Phillies",
"Chicago Cubs", "Milwaukee Brewers", "St. Louis Cardinals", "Pittsburgh Pirates", "Cincinnati Reds", "Los Angeles Dodgers", "Arizona Diamondbacks",
"Colorado Rockies", "San Diego Padres", "San Francisco Giants" };
string[] state = { "MA", "NY", "FL", "CN", "MD", "OH", "MN", "MO", "IL", "MI", "TX", "CA", "WA", "TX", "CA", "DC",
"FL", "GA", "NY", "PA", "IL", "WI", "MO", "PA", "OH", "CA", "AZ", "CO", "CA", "CA" };
string[] clinch = { "x", "y", "n", "n", "n", "*", "y", "n", "n", "n", "x", "n", "n", "n", "n", "x", "n", "n",
"n", "n", "x", "n", "n", "n", "n", "*", "y", "y", "n", "n" };
string[] divison = { "ALE", "ALE", "ALE", "ALE", "ALE", "ALC", "ALC", "ALC", "ALC", "ALC", "ALW", "ALW", "ALW", "ALW", "ALW", "NLE", "NLE", "NLE", "NLE", "NLE", "NLC", "NLC", "NLC",
"NLC", "NLC", "NLW", "NLW", "NLW", "NLW", "NLW" };
int[] wins = { 93, 91, 80, 76, 75, 102, 85, 80, 67, 64, 101, 80, 78, 78, 75, 97, 77, 72, 70, 66, 92, 86, 83, 75, 68, 104, 93, 87, 71, 64 };
int[] losses = { 69, 71, 82, 86, 87, 60, 77, 82, 95, 98, 61, 82, 84, 84, 87, 65, 85, 90, 92, 96, 70, 76, 79, 87, 94, 58, 69, 75, 91, 98 };
int[] runsScored = { 785, 858, 694, 693, 743, 818, 815, 702, 706, 735, 896, 710, 750, 799, 739, 819, 778, 732, 735, 690, 822, 732, 761, 668, 753, 770, 812, 824, 604, 639 };
int[] runsAgainst = { 668, 660, 704, 784, 841, 564, 788, 791, 820, 894, 700, 709, 772, 816, 826, 672, 822, 821, 863, 782, 695, 697, 705, 731, 869, 580, 659, 757, 816, 776 };
divNL(teams, state, clinch, divison, wins, losses, runsScored, runsAgainst, wins, losses);
divAL(teams, state, clinch, divison, wins, losses, runsScored, runsAgainst, losses, runsScored);
}
static void divNL(string[] t, string[] state, string[] c, string[] d, int[] w, int[] l, int[] r, int[] s, int[] p, int[] o)
{
// displays all info for NL division
string stateM = "";
double pctWins = 0.0;
double raRS = 0.0;
int win = 0, loss = 0;
int aR = 0, sR = 0;
pctWins = (double)win / (win + loss);
raRS = (double)aR - sR;
Console.WriteLine("All Data for NL Division Teams");
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "Team", "State", "Clinch", "Div", "W", "L", "RS", "RA", "WinPCT", "RA/RS");
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----", "----", "-----", "----", "-----", "----", "-----", "-----");
for (int i = 0; i < state.Length; ++i)
{
if (state[i] == "NLC" | state[i] == "NLW" | state[i] == "NLE")
{
stateM = state[i];
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
w[i], l[i], r[i], s[i], pctWins, raRS);
}
}
}
static void divAL(string[] t, string[] state, string[] c, string[] d, int[] w, int[] l, int[] r, int[] s, int[] p, int[] o)
{
//displays all info for Al divsion
string stateM = "";
double pctWins = 0.0;
double raRS = 0.0;
int win = 0, loss = 0;
int aR = 0, sR = 0;
pctWins = (double)win / (win + loss);
raRS = (double)aR - sR;
Console.WriteLine("\n\nAll Data for AL Division Teams\n");
Console.WriteLine("{0,20}{1,8}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,8}{9,8}", "Team", "State", "Clinch", "Div", "W", "L", "RS", "RA", "WinPCT", "RA/RS");
Console.WriteLine("{0,20}{1,8}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,8}{9,8}", "----", "-----", "----", "----", "-----", "----", "-----", "----", "-----", "-----");
for (int i = 0; i < state.Length; ++i)
{
if (state[i] == "ALC" | state[i] == "ALE" | state[i] == "ALE")
{
stateM = state[i];
Console.WriteLine("{0,8}{1,8}{2,8}{3,8}{4,8}{5,8}{6,8}{7,8}{8,8}{9,8}", t[i], state[i], c[i], d[i],
w[i], l[i], r[i], s[i], pctWins, raRS);
}
}
}
答案 0 :(得分:1)
你忘记了这些行中的一些开口花括号:
Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
"----", "-----", "----", "-----", "----", "-----", "-----");
Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
w[i], l[i], r[i], s[i], pctWins, raRS);
Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
"----", "-----", "----", "-----", "----", "-----", "-----");
Console.WriteLine("0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
w[i], l[i], r[i], s[i], pctWins, raRS);
他们应该如下:
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
"----", "-----", "----", "-----", "----", "-----", "-----");
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
w[i], l[i], r[i], s[i], pctWins, raRS);
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", "----", "-----", "----",
"----", "-----", "----", "-----", "----", "-----", "-----");
Console.WriteLine("{0,24}{1,18}{2,18}{3,18}{4,18}{5,18}{6,18}{7,18}{8,18}{9,18}", t[i], state[i], c[i], d[i],
w[i], l[i], r[i], s[i], pctWins, raRS);
提示:
使用$""
字符串格式可以减少错误。