Chapter 2 C#语句---选择语句

选择语句(条件语句):
1、 if
if...else if...else if...else
2、 switch case 1 case 2 ... case n default

1
//case 1:成绩 2 Console.Write("请输入姓名:"); 3 Console.ReadLine(); 4 Console.WriteLine("请输入分数:"); 5 double a = double.Parse(Console.ReadLine()); 6 if(a>=80 && a<=100) 7 { 8 Console.WriteLine("学得不错,值得表扬!"); 9 } 10 if (a >= 60 && a < 80) 11 { 12 Console.WriteLine("还不错,再加把劲!"); 13 } 14 if (a >= 50 && a < 60) 15 { 16 Console.WriteLine("就差一点点,再加把劲!"); 17 } 18 if (a >= 0 && a < 50) 19 { 20 Console.WriteLine("使劲努力,不要偷懒!"); 21 } 22 else 23 { 24 Console.WriteLine("您的输入有误"); 25 } 26 Console.ReadLine();

 1 //case 2:标准体重
 2             Console.Write("请输入性别:");
 3             string s = Console.ReadLine();
 4             Console.Write("请输入体重:");
 5             double w = double.Parse(Console.ReadLine());
 6             Console.Write("请输入身高:");
 7             double h = double.Parse(Console.ReadLine());
 8             if(s=="")
 9             {
10                 double m = w - h + 100;
11                 if(m>=-3 && m<=3)
12                 {
13                     Console.WriteLine("您的体重是标准体重!");
14                 }
15                 else if (m > 3)
16                 { 
17                     Console.WriteLine("您需要减肥了!");
18                 }
19                 else 
20                 {
21                     Console.WriteLine("您需要补充营养!");
22                 }
23             }
24             else if (s == "")
25             {
26                 double f = w - h + 110;
27                 if (f >= -3 && f <= 3)
28                 {
29                     Console.WriteLine("您的体重是标准体重!");
30                 }
31                 if (f > 3)
32                 {
33                     Console.WriteLine("您需要减肥了!");
34                 }
35                 else
36                 {
37                     Console.WriteLine("您需要补充营养!");
38                 }
39             }
40             else 
41             {
42                 Console.WriteLine("您的输入有误!");
43             }
44             Console.ReadLine();

 1  //case 3:月份
 2             int m1 = 31, m2 = 28, m3 = 31, m4 = 30, m5 = 31, m6 = 30,
 3                 m7 = 31, m8 = 31, m9 = 30, m10 = 31, m11 = 30;
 4             Console.WriteLine("请输入月份:");
 5             int mm = int.Parse(Console.ReadLine());
 6             Console.WriteLine("请输入日期:");
 7             int d = int.Parse(Console.ReadLine());
 8             switch(mm)
 9             {
10             case 1:
11                 Console.WriteLine(""+d+"");
12                 break;
13             case 2:
14                 Console.WriteLine(""+(d+m1).ToString()+"");
15                 break;
16             case 3:
17                 Console.WriteLine(""+(d+m1+m2).ToString()+"");
18                 break;
19             case 4:
20                 Console.WriteLine(""+(d+m1+m2+m3).ToString()+"");
21                 break;
22             case 5:
23                 Console.WriteLine(""+(d+m1+m2+m3+m4).ToString()+"");
24                 break;
25             case 6:
26                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5).ToString()+"");
27                 break;
28             case 7:
29                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5+m6).ToString()+"");
30                 break;
31             case 8:
32                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5+m6+m7).ToString()+"");
33                 break;
34             case 9:
35                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5+m6+m7+m8).ToString()+"");
36                 break;
37             case 10:
38                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5+m6+m7+m8+m9).ToString()+"");
39                 break;
40             case 11:
41                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5+m6+m7+m8+m9+m10).ToString()+"");
42                 break;
43             case 
44                 12:
45                 Console.WriteLine(""+(d+m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11).ToString()+"");
46                 break;
47             default:
48                 Console.WriteLine("您的输入有误");
49                 break;
50             }
51             Console.ReadLine();

posted @ 2016-05-04 15:12  庚xiao午  阅读(128)  评论(0编辑  收藏  举报