码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-07-31 17:37:16      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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();

       

           }    

     }

}

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

标签:

原文地址:http://www.cnblogs.com/xiaobao5161/p/5723305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!