C#/C#200제

[C#] 7일차 - 42. BMI계산기

반나무 2021. 1. 22. 11:13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A042_BMI
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("키를 입력하세요(cm) : ");
            double height = Double.Parse(Console.ReadLine());
            height /= 100; // m단위로 변경

            Console.Write("체중을 입력하세요(kg) : ");
            double weight = Double.Parse(Console.ReadLine());
            double bmi = weight / (height * height);

            string comment = null;
            if (bmi < 20)
                comment = "저체중";
            else if (bmi < 25)
                comment = "정상체중";
            else if (bmi < 30)
                comment = "경도비만";
            else if (bmi < 40)
                comment = "비만";
            else
                comment = "고도비만";

            Console.WriteLine("BMI={0:F1}, \"{1}\"입니다.", bmi, comment);

        }
    }
}

반응형