編寫一段程序,運行時向用戶提問“你考了多少分?(0~100)”,接受輸入后判斷其等級並顯示出來。判斷依據如下:等級={優 (90~100分);良 (80~89分);中 (60~69分);差 (0~59分);}
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 貼吧01 8 { 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 int input; 14 //Console.WriteLine("你考了多少分?(0~100)"); 15 while (true) 16 { 17 Console.WriteLine("你考了多少分?(0~100)"); 18 input = Convert.ToInt32(Console.ReadLine()); 19 if ((input >= 90) && (input <= 100)) 20 { 21 Console.WriteLine("優"); 22 break; 23 } 24 else if (input >= 80) 25 { 26 Console.WriteLine("良"); 27 break; 28 } 29 else if ((input >= 60) && (input <= 69)) 30 { 31 Console.WriteLine("中"); 32 break; 33 } 34 else if ((input >= 0) && (input <= 59)) //0-59 35 { 36 Console.WriteLine("差"); 37 break; 38 } 39 else 40 { 41 Console.WriteLine("輸入有誤或者所輸入的不是要求的有效成績范圍"); 42 } 43 } 44 Console.ReadKey(); 45 } 46 } 47 }
