注意:理清逻辑,画出逻辑分支图,理清思路
1.if语句
2.if...else语句
3.if..else if...else
1 static void Main(string[] args) 2 { 3 Console.WriteLine("输入分数:"); 4 5 string fs = Console.ReadLine(); 6 int score = Convert.ToInt32(fs); 7 8 #region 判断分数 9 if (score >= 0 && score < 60) 10 { 11 Console.WriteLine("不及格,补考"); 12 } 13 else if (score >= 60 && score < 80) 14 { 15 Console.WriteLine("恭喜及格"); 16 } 17 else if (score >= 80 && score <= 100) 18 { 19 Console.WriteLine("恭喜优秀"); 20 } 21 else 22 { 23 Console.WriteLine("输入有误"); 24 } 25 #endregion 26 27 Console.WriteLine("结束"); 28 }
3.输入分数,如果小于60,再判断加分项,然后输出是否及格
1 static void Main(string[] args) 2 { 3 Console.WriteLine("输入分数:"); 4 5 string fs = Console.ReadLine(); 6 int score = Convert.ToInt32(fs); 7 8 if (score < 60) 9 { 10 Console.WriteLine("是否认真做作业?(是,否)"); 11 12 string zuoye = Console.ReadLine(); 13 14 #region ======加分======= 15 if (zuoye == "是") 16 { 17 score = score + 5; 18 19 if (score < 60) 20 { 21 Console.WriteLine("不及格"); 22 } 23 else 24 { 25 Console.WriteLine("凑合及格"); 26 } 27 } 28 else 29 { 30 Console.WriteLine("不及格了"); 31 } 32 #endregion 33 } 34 else 35 { 36 37 } 38 39 Console.WriteLine("结束"); 40 }
VS复习 -- if···else和if···else嵌套语句
原文:http://www.cnblogs.com/kellybutterfly/p/5399607.html