习题一:
做一个算缘分的小游戏:
输入男方姓名,女方姓名,输出缘分指数,给出建议。
static void Main(string[] args) { //做一个算缘分的小游戏: //输入男方姓名,女方姓名,输出缘分指数,给出建议。 Console.WriteLine("男方姓名:"); string nan = Console.ReadLine(); Console.WriteLine("女方姓名:"); string nv = Console.ReadLine(); Random r = new Random(); int n = r.Next(100); string jianyi = ""; if (n>0&&n<30) { jianyi="有缘无分,分手吧"; } else if (n>=30&&n<60) { jianyi="一起努力吧!"; } else if (n>=60&&n<80) { jianyi="幸福一对"; } else { jianyi="佳偶天成,珠联璧合"; } Console.WriteLine("{0}和{1}的缘分指数是:{2}。建议:{3}",nan,nv,n,jianyi); }
习题二:相亲
1 static void Main(string[] args) 2 { 3 //相亲 4 string fangzi, piaozi, nengli; 5 Console.Write("女神:有房子吗?"); 6 fangzi = Console.ReadLine(); 7 if (fangzi == "有") 8 { 9 Console.WriteLine("女神:咱们结婚吧"); 10 } 11 else 12 { 13 Console.Write("女神:有钱吗?"); 14 piaozi = Console.ReadLine(); 15 if (piaozi=="有") 16 { 17 Console.WriteLine("女神:用钱买房子结婚吧"); 18 } 19 else 20 { 21 Console.Write("女神:有能力吗?"); 22 nengli = Console.ReadLine(); 23 if (nengli=="有") 24 { 25 Console.WriteLine("女神:赶紧赚钱,买房子,结婚吧"); 26 } 27 else 28 { 29 Console.WriteLine("女神:拜拜"); 30 } 31 32 } 33 34 } 35 36 }
习题三:睡觉突然醒了,反应现在是几点,是否起床
1 static void Main(string[] args) 2 { 3 //做梦醒了,看看时间,是否起床 4 int shijian, xingqi; 5 Console.WriteLine("几点了?"); 6 shijian = Convert.ToInt32(Console.ReadLine()); 7 if (shijian<8) 8 { 9 Console.WriteLine("还早呢,再睡会"); 10 } 11 else 12 { 13 Console.WriteLine("今天星期几?"); 14 xingqi = Convert.ToInt32(Console.ReadLine()); 15 if (xingqi==2||xingqi==5) 16 { 17 Console.WriteLine("不上课,接着睡"); 18 } 19 else 20 { 21 Console.WriteLine("赶紧起床,不然要迟到了"); 22 } 23 } 24 }
习题四:模拟彩票中奖,计算机随机生成3个100以内的数,人类输入5个数,看是否中奖
1 static void Main5555(string[] args) 2 3 { 4 //计算机生成100以内的3个数,输入5个数,输出中奖 5 //颜色显示 6 Console.ForegroundColor = ConsoleColor.DarkYellow; 7 8 int caiduigeshu = 0; 9 10 //计算机随机输出 11 Random random = new Random(); 12 int a = random.Next(100); 13 int b= random.Next(100); 14 int c = random.Next(100); 15 16 //人类输入 17 Console.WriteLine("*************请输入5个100以内的数:****************"); 18 Console.WriteLine("第一个数是:"); 19 int x1 = Convert.ToInt32(Console.ReadLine()); 20 Console.WriteLine("第二个数是:"); 21 int x2 = Convert.ToInt32(Console.ReadLine()); 22 Console.WriteLine("第三个数是:"); 23 int x3 = Convert.ToInt32(Console.ReadLine()); 24 Console.WriteLine("第四个数是:"); 25 int x4 = Convert.ToInt32(Console.ReadLine()); 26 Console.WriteLine("第五个数是:"); 27 int x5 = Convert.ToInt32(Console.ReadLine()); 28 //清屏 29 Console.Clear(); 30 Console.WriteLine("电脑随机生成的数是:{0},{1},{2}",a,b,c); 31 32 //运算输出 33 if (a==x1||b==x1||c==x1) 34 { 35 caiduigeshu++; 36 37 } 38 if (a == x2 || b == x2 || c == x2) 39 { 40 caiduigeshu++; 41 } 42 if (a == x3 || b == x3 || c == x3) 43 { 44 caiduigeshu++; 45 } 46 if (a == x4 || b == x4 || c == x4) 47 { 48 caiduigeshu++; 49 } 50 if (a == x5 || b == x5 || c == x5) 51 { 52 caiduigeshu++; 53 } 54 55 if (caiduigeshu==0) 56 { 57 Console.WriteLine("谢谢参与"); 58 } 59 else if (caiduigeshu==1) 60 { 61 62 Console.WriteLine("恭喜你中了10元"); 63 } 64 else if (caiduigeshu==2) 65 { 66 Console.WriteLine("恭喜你中了100元"); 67 } 68 else if (caiduigeshu==3) 69 { 70 Console.WriteLine("恭喜你中了1000元"); 71 } 72 else 73 { 74 Console.WriteLine("恭喜你中了100万"); 75 } 76 77 }
习题五:输入应发工资,输出所交税费和税后工资
个人所得税的计算方法:
1 static void Main(string[] args) 2 { 3 //作业:输入应发工资,输出所交税费和税后工资 4 5 double yfgz, shuifei, shgz; 6 double m1 = 0.03, k1 = 0; 7 double m2 = 0.1, k2 = 105; 8 double m3 = 0.2, k3 = 555; 9 double m4 = 0.25, k4 =1005; 10 double m5 = 0.3, k5 = 2755; 11 double m6 = 0.35, k6 = 5505; 12 double m7 = 0.45, k7 = 13505; 13 14 //输入 15 Console.WriteLine("请输入应发工资:"); 16 yfgz = Convert.ToDouble(Console.ReadLine()); 17 double s=yfgz-3500; // 18 19 20 21 //运算 22 if (yfgz<=3500) 23 { 24 shuifei = 0; 25 shgz = yfgz; 26 Console.WriteLine("不用交税\n税后工资是:"+shgz); 27 Console.WriteLine("应交税费是:" + shuifei); 28 } 29 else 30 { 31 if (s>0&&s<=1500) 32 { 33 shuifei = s*m1-k1; 34 shgz = yfgz-shuifei; 35 Console.WriteLine("税后工资是:"+shgz); 36 Console.WriteLine("应交税费是:" + shuifei); 37 } 38 else if (s>1500&&s<=4500) 39 { 40 shuifei = s * m2 - k2; 41 shgz = yfgz - shuifei; 42 Console.WriteLine("税后工资是:" + shgz); 43 Console.WriteLine("应交税费是:" + shuifei); 44 } 45 else if (s > 4500 && s <= 9000) 46 { 47 shuifei = s * m3 - k3; 48 shgz = yfgz - shuifei; 49 Console.WriteLine("税后工资是:" + shgz); 50 Console.WriteLine("应交税费是:" + shuifei); 51 } 52 else if (s > 9000 && s <= 35000) 53 { 54 shuifei = s * m4 - k4; 55 shgz = yfgz - shuifei; 56 Console.WriteLine("税后工资是:" + shgz); 57 Console.WriteLine("应交税费是:" + shuifei); 58 } 59 else if (s > 35000 && s <= 55000) 60 { 61 shuifei = s * m5 - k5; 62 shgz = yfgz - shuifei; 63 Console.WriteLine("税后工资是:" + shgz); 64 Console.WriteLine("应交税费是:" + shuifei); 65 } 66 else if (s > 55000 && s<=80000) 67 { 68 shuifei = s * m6 - k6; 69 shgz = yfgz - shuifei; 70 Console.WriteLine("税后工资是:" + shgz); 71 Console.WriteLine("应交税费是:" + shuifei); 72 } 73 else 74 { 75 shuifei = s * m7 - k7; 76 shgz = yfgz - shuifei; 77 Console.WriteLine("税后工资是:" + shgz); 78 Console.WriteLine("应交税费是:" + shuifei); 79 } 80 } 81 }
时间: 2024-10-22 10:02:57