iOS小記--使用結構體處理資料表的問題

weixin_34019929發表於2015-10-08

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;

}

}

相關文章