编写标准体重程序是什么

时间:2025-01-27 16:51:08 手机游戏

编写标准体重程序可以根据不同的编程语言和需求有所不同。以下是几种不同编程语言编写标准体重程序的示例:

Python 示例

```python

def calculate_standard_weight(height, gender):

if gender == '男':

return height - 105

elif gender == '女':

return height - 100

else:

return None

def main():

print("选择性别:")

gender = input("1: 男\t2: 女 ")

height = int(input("请输入身高(cm): "))

weight = int(input("请输入体重(kg): "))

standard_weight = calculate_standard_weight(height, gender)

if standard_weight is not None:

print(f"标准体重: {standard_weight} kg")

这里可以添加更多的体重状态判断逻辑

if __name__ == "__main__":

main()

```

C++ 示例

```cpp

include

using namespace std;

int main() {

double height, weight, bweight;

cout << "请输入身高(cm): ";

cin >> height;

cout << "请输入体重(kg): ";

cin >> weight;

bweight = height - 100;

if (weight > bweight * 1.2)

cout << "体重超重,请控制饮食和增加运动。" << endl;

else if (weight < bweight * 0.8)

cout << "体重超轻,请增加营养和适当运动。" << endl;

else

cout << "体重正常,请继续保持。" << endl;

return 0;

}

```

C 示例

```csharp

using System;

class Program

{

static void Main()

{

Console.WriteLine("请输入性别:");

string gender = Console.ReadLine();

Console.WriteLine("请输入身高(cm):");

double height = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("请输入体重(kg):");

double weight = Convert.ToDouble(Console.ReadLine());

double standardWeight = gender == "男" ? height - 105 : height - 100;

Console.WriteLine($"标准体重: {standardWeight} kg");

// 这里可以添加更多的体重状态判断逻辑

}

}

```

Java 示例

```java

import java.util.Scanner;

public class StandardWeightCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("请输入性别:");

String gender = scanner.next();

System.out.println("请输入身高(cm):");

double height = scanner.nextDouble();

System.out.println("请输入体重(kg):");

double weight = scanner.nextDouble();

double standardWeight = gender.equals("男") ? height - 105 : height - 100;

System.out.println("标准体重: " + standardWeight + " kg");

// 这里可以添加更多的体重状态判断逻辑

}

}

```

JavaScript 示例

```javascript

function calculateStandardWeight(height, gender) {

if (gender === '男') {

return height - 105;

} else if (gender === '女') {

return height - 100;

} else {

return null;

}

}

function main() {

console.log("请输入性别:");

const gender = prompt("1: 男\t2: 女");

console.log("请输入身高(cm):");

const height = parseInt(prompt("请输入身高(cm):"), 10);

console.log("请输入体重(kg):");

const weight = parseInt(prompt("请输入体重(kg):"), 10);

const standardWeight = calculateStandardWeight(height, gender);

if (standardWeight !== null) {

console.log(`标准体重: ${standardWeight} kg`);

// 这里可以添加更多的体重状态判断逻辑

}

}

main();

```

这些示例展示了如何使用不同编程语言编写一个简单的标准体重计算程序。你可以根据自己的需求选择合适的编程语言,并根据实际情况添加更多的功能和逻辑。