안녕하세요! 오유징어 && 스르륵에서 오신 아재 여러분!!
얼마전에 비슷한 질문 글을 올렸는데 몇가지가 해결이 안되서 이렇게 다시 염치없게 질문 합니다 :-)
bmi 계산 하는 건데요. 몸무게와 키를 입력 할때 kg, lbs, m, cm, ft, in 단위를 사용 할때에 문제 없이 값이 나오는데
'(feet) "(inch) 심볼을 사용해서 입력 하려면 어떻게 해야 하는지 알려 주시면 당신은 멋쟁이!!!
요약: 5ft6in 를 5'6" 입력하고 싶습니다 ㅠㅠ
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
double weight_convert(double, string);
double height_convert(double, string);
int main()
{
double weight;
double height;
// double height_add;
string weight_unit;
string height_unit;
// string height_unit_add;
string and;
cout << "Welcome to BMI Calculator!" << endl;
cout << "--------------------------" << endl;
cout << "Enter your weight in kg or lb and height in m, cm, ft, or in: ";
cin >> weight;
cin >> weight_unit;
cin >> and;
cin >> height;
cin >> height_unit;
// bmi formular using double, pow
double bmi = weight_convert(weight, weight_unit) / pow(height_convert(height, height_unit), 2);
cout << "\nBMI: " << fixed << setprecision(3) << bmi << endl;
// name: category
// return: if
// purpose: to determine the category of the person depends upon the BMI calculated
// accept: if, else if
if (bmi < 15)
{
cout << "You are very severely underweight.\n";
}
else if (bmi >= 15.0 && bmi < 16.0)
{
cout << "You are severely underweight.\n";
}
else if (bmi >= 16.0 && bmi < 18.5)
{
cout << "You are underweight.\n";
}
else if (bmi >= 18.5 && bmi < 25)
{
cout << "You are normal(Healthy weight!)\n";
}
else if (bmi >= 30 && bmi < 35)
{
cout << "You are obese class 1 (Moderately obese!)\n";
}
else if (bmi >= 35 && bmi < 40)
{
cout << "You are obese class 2 (Severely obese!)\n";
}
else if (bmi >= 40)
{
cout << "You are obese class 3 (Very severely obese!)\n";
}
}
// name: weight_convert
// return: double
// purpose: to convert other units into 'kg'
// accept: double, string
double weight_convert(double weight, string unit)
{
if (unit == "lb")
return weight * 0.453592;
else if (unit == "kg")
return weight;
cout << "Error: Invalid input. Please try again!" << endl;
exit(0);
}
double height_convert(double height, string unit)
{
if (unit == "m")
return height;
else if (unit == "cm")
return height * 0.01;
else if (unit == "ft")
return height * 0.3048;
else if (unit == "in")
return height * 0.0254;
cout << "Error: Invalid input. Please try again!" << endl;
exit(0);
}