C#学习7.31判断体重是否超标

using System;

using System.Collections.Generic;

using System.Linq; using System.Text;

using System.Threading.Tasks;

namespace 练习1

{    

//要求写一个函数判断体重是否超标

//函数具有三个参数,分别是性别、体重(Kg)、身高(cm)

//辨别方法:“男”  身高-100=体重+/-3 ;“女”  身高-110=体重+/-3 

 

class Program    

       {        

            public string celing(string sex,int heavy ,int hight)    

             {                  

                   if (sex == "男")           

                  {                

                          if (hight - 100 == heavy + 3 || hight - 100 == heavy - 3)                

                            {                    

                                    return "您的体重标准!";

                            }                

                            else                

                           {                   

                                     return "您的体重不达标!";

                            }            

                  }            

                  else if (sex == "女")           

                 {                

                          if (hight - 110 == heavy + 3 || hight - 110 == heavy - 3)               

                          {                     

                                   return "您的体重标准!";

                        }               

                          else              

                        {                   

                                   return "您的体重不达标!";

                        }

                }            

               else                

                        return "您的输入有误,请重试!";     

               }

 

             static void Main(string[] args)      

           {

                     Console.Write("请输入您的性别:");        

                     string sex = Console.ReadLine();            

                     Console.Write("请输入您的体重:请用Kg表示)");          

                     int heavy = int.Parse(Console.ReadLine());            

                     Console.Write("请输入您的身高:(请用cm表示)");           

                     int hight = int.Parse(Console.ReadLine());            

                     Console.WriteLine("输入完毕请按回车键打印!");            

                     Console.ReadLine();            

                    Program hanshu = new Program();           

                    Console.Write("您的性别是:{0},体重{1}Kg,身高{2}cm,",sex ,heavy ,hight );         

                    Console.WriteLine(hanshu.celing(sex,heavy ,hight ));

                    Console.ReadLine();

       

           }    

     }

}

转载于:https://www.cnblogs.com/xiaobao5161/p/5723305.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值