C#/Foundation
004. 실수(double)로 키(cm)와 체중(kg)을 입력받아 BMI를 계산하고 비만정도를 출력하시오
페프
2021. 3. 25. 01:46
if~else 조건문을 사용하여 bmi 계산을 해보았다.
004. 실수(double)로 키(cm)와 체중(kg)을 입력받아 BMI를 계산하고 비만정도를 출력하시오
#include using namespace std; int main() { int height, weight; cout << "키(cm): "; cin >> height; cout << "체중(kg) :"; cin >> weight; double bmi = weight / (height / 100.0 * height / 100.0); cout <..
ffeff45.tistory.com
위에 링크는 C++으로 같은 문제를 짜보았던 것이다.
bmi 계산기는 입출력을 제외하곤 C++과 똑같았다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B004
{
class Program
{
static void Main(string[] args)
{
double height, weight;
Console.Write("키를 입력하세요(cm) : ");
height = double.Parse(Console.ReadLine());
Console.Write("몸무게를 입력하세요(kg) : ");
weight = double.Parse(Console.ReadLine());
height = height / 100;
double bmi = weight / (height * height);
Console.WriteLine("BMI = {0}", bmi);
if (bmi < 20)
Console.WriteLine("저체중");
else if (bmi < 25)
Console.WriteLine("정상체중");
else if (bmi < 30)
Console.WriteLine("경도비만");
else if (bmi < 40)
Console.WriteLine("비만");
else
Console.WriteLine("고도비만");
}
}
}