我想顯示一個數組本身沒有問題。但是,我想添加一個If statement
,這樣如果正在顯示的score[]
陣列的當前迭代等於300,那麼它將在其後面放置一個*
。就像300*
C#顯示陣列的格式化內容
此外陣列需要顯示從最高到最低,我正在通過顛倒顯示在陣列中的最低點到最高點。我正在考慮使用交換來改變順序,但如果我不必那麼我想這樣解決它。
到目前爲止,我得到
400
332
300*
300
或以另一種方式我試過了,我得到了
0
0
300*
300
250
221
我只具有顯示和輸出的問題。
static void Output(int iteration, int[] score, string[] player, double average)
{ //opening output
Console.WriteLine("\n\t****** OUTPUT ******");
Console.WriteLine("\nScores for this game.\n");
if (score[iteration - 1] == 300)
{
Console.WriteLine("{0} score was {1}*", player[iteration - 1], score[iteration - 1]);
}
for (int i = iteration; i <= MAX_SIZE_ARRAY; i--)
{
//iterates through the loop to display all the players name then score
Console.WriteLine("{0} score was {1}", player[i], score[i]);
}
//displays high, low, and average score
Console.WriteLine("\nThe high score was {0} with {1} points", player[iteration - 1], score[iteration - 1]);
Console.WriteLine("The low score was {0} with {1} points", player[0], score[0]);
Console.WriteLine("The team average score was {0}", average);
}
}
}
你只需要移動你的if語句中的for循環? – Greg 2012-07-15 23:35:08
我確實嘗試過,但它也給出了不理想的結果 – Dan 2012-07-15 23:37:30
您能否提供一個數據樣本?另外在你的for循環中它是否需要i> 0? – Greg 2012-07-15 23:44:47