The requirements have the two first fun to be in ViewModel. val f and run are in Main Activity. The loop is stopping. I think there might be an issue toFloat(). Is there something that I am missing? Thank you for the help.
val f = bmiViewModel.updatebmi(bmiViewModel.formula(inc, wt, ft))
run(f)
fun formula(inc: Int, ft: Int, wt: Int): Float {
val htTotal = (ft*12).toFloat() + inc.toFloat()
val BMI = (wt.toFloat()*703) / (htTotal * htTotal)
Log.d(TAG,"BMI", Exception())
return BMI
fun updatebmi(total: Float): Int{
if (total < 18.5) {
return -256
} else if (total >= 18.5 && total < 24.9) {
return 8
} else if (total >= 24.9 && total < 30) {
return 256
} else{
return 16
}
}
private fun run(i: Int){
if (i == -256) {
binding.status.text = "Under Weight"
binding.status.setTextColor(i)
} else if (i == 8) {
binding.status.text = "Normal"
binding.status.setTextColor(i)
} else if (i == 256) {
binding.status.text = "Overweight"
binding.status.setTextColor(-256)
} else{
binding.status.text = "Obese"
binding.status.setTextColor(16)
}