功能需求:
人每时每刻都在消耗能量,使用BMR(Basic Metabolic Rate)来计算人全无活动(睡一整天)时所需的热量。下面介绍人每天至少需要多少热量(附热量计算公式)?女: BMR = 65.5 + ( 9.6 × 体重kg ) + ( 1.8 × 身高cm ) - ( 4.7 × 年龄years )男: BMR = 66 + ( 13.7 × 体重kg ) + ( 5 × 身高cm ) - ( 6.8 × 年龄years )请同学们编写程序计算你每天的基础代谢率BMR。
- #include
- int main() {
- int gender;
- double weight, height, age, bmr;
- printf("请选择性别(1代表女性,2代表男性):");
- scanf("%d", &gender);
- printf("请输入体重(kg):");
- scanf("%lf", &weight);
- printf("请输入身高(cm):");
- scanf("%lf", &height);
- printf("请输入年龄(岁):");
- scanf("%lf", &age);
- if (gender == 1) {
- bmr = 65.5 + (9.6 * weight) + (1.8 * height) - (4.7 * age);
- } else if (gender == 2) {
- bmr = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);
- } else {
- printf("无效的性别选择。\n");
- return 0;
- }
- printf("您每天的基础代谢率(BMR)为:%.2lf千卡。\n", bmr);
- return 0;
- }
- #include
- using namespace std;
- int main() {
- int gender;
- double weight, height, age, bmr;
- cout << "请选择性别(1代表女性,2代表男性):";
- cin >> gender;
- cout << "请输入体重(kg):";
- cin >> weight;
- cout << "请输入身高(cm):";
- cin >> height;
- cout << "请输入年龄(岁):";
- cin >> age;
- if (gender == 1) {
- bmr = 65.5 + (9.6 * weight) + (1.8 * height) - (4.7 * age);
- } else if (gender == 2) {
- bmr = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);
- } else {
- cout << "无效的性别选择。" << endl;
- return 0;
- }
- cout << "您每天的基础代谢率(BMR)为:" << bmr << "千卡。" << endl;
- return 0;
- }
请注意,这只是一个简单的示例代码,没有进行输入验证和错误处理。在实际应用中,你可能需要添加更多的代码来确保输入的有效性和程序的健壮性。