欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#循环接收学员成绩并输出总分和平均分

程序员文章站 2022-06-24 16:31:39
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _14_Ex_While { static void Main() { Console.Write("请输入班级人数:"); int nop = Convert.ToInt32(Console.ReadLine()...
using System;
using System.Collections.Generic;
using System.Text;

namespace KnowledgePoint
{
    class _14_Ex_While
    {
        static void Main()
        {
            Console.Write("请输入班级人数:");
            int nop = Convert.ToInt32(Console.ReadLine());
            double sumScore = 0.0; // 总成绩
            int i = 1; // 循环变量
            while (i <= nop)
            {
                Console.Write("\n请输入第 {0} 个学员的成绩:", i);
                int score = Convert.ToInt32(Console.ReadLine());
                sumScore += score; // 循环接收每次输入的学员成绩
                i++; // 循环变量自增
            }
            Console.Write("\n提示:班级人数{0},总分{1},平均分{2}", nop, sumScore, (sumScore / nop));

            Console.ReadKey();
        }
    }
}

本文地址:https://blog.csdn.net/qq_44965393/article/details/107295613