#代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Console.WriteLine("請輸入班級人數(shù)");
? ? ? ? ? ? int count = Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? int i = 0;//聲明一個循環(huán)變量,記錄循環(huán)的次數(shù)
? ? ? ? ? ? int sum = 0;//定義總成績
? ? ? ? ? ? while (i < count)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("請輸入第{0}個學(xué)員的成績", i + 1);
? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int score = Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? ? ? ? ? //將每一個學(xué)員的成績累加到總成績中
? ? ? ? ? ? ? ? ? ? sum += score;
? ? ? ? ? ? ? ? ? ? i++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? catch
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("輸入有誤,請重新輸入");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine("{0}個人的班總成績是{1}平均成績是{2}", count, sum, sum / count);
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}
#效果