7.C#--if else-if 分支語句使用

static void Main(string[] args)
{
//用if else-if對學員的結業考試成績評測
//成績>=90 :A
//90>成績>=80 :B
//80>成績>=70 :C
//70>成績>=60 :D
//成績<60 :E

        Console.WriteLine("請輸入這次考試的成績");         //提示輸入考試成績
        int score = Convert.ToInt32(Console.ReadLine());   //輸入考試成績
        //對輸入的成績進行等級評定
        if(score >= 90)
        {
            Console.WriteLine("成級評定爲:A");
        }
        else if (score >= 80)
        {
            Console.WriteLine("成績評定爲:B");
        }
        else if (score >= 70)
        {
            Console.WriteLine("成績評定爲:C");
        }
        else if (score >= 60)
        {
            Console.WriteLine("成績評定爲:D");
        }
        else
        {
            Console.WriteLine("成績評定爲:E");
        }
        Console.ReadKey();
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章