1.自定义结构题bmiUnit
struct bmiUnit{
float begin;
float suspend;
float bmiScore;
}bmiUnit;
2.初始化static 结构体数组BMI[7]
static struct bmiUnit BMI[7] = {
{0 ,18.5 ,90},
{18.6 ,23.9 ,100},
{24 ,24 ,95},
{24.1 ,26.9 ,95},
{27 ,29.9 ,85},
{30 ,39.9 ,80},
{40 ,100 ,75},
};
3.应用
for (int i = 0; i < 7; i ++) {
struct bmiUnit bmiU = BMI[i];
if (bmiU.begin <= bmi && bmi <= bmiU.suspend) {
return bmiScore = bmiU.bmiScore;
}
}