Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 212043

Problem with a loop in bmi calculator R language

$
0
0

I have problem with school task -> BMI calculator Here is my code

 #Przedziały
niedowaga <- seq(16.00, 18.40, 0.01)
norma <- seq(18.50, 24.90, 0.01)
nadwaga <- seq(25.00, 30.00, 0.01)
print(niedowaga)
print(norma)
print(nadwaga)
 #Pytanie
waga = as.integer(readline(prompt="Podaj swoją wagę: "))
wzrost = as.integer(readline(prompt="Podaj swój wzrost w cm: "))
 #Formuła
bmi <- waga/wzrost**2 * 10000
 #Zaokrąglenie BMI do jednej liczby po przecinku
bmi_round <-round(bmi, digits = 2)
 #Wyświetlenie wartości BMI po zaokrągleniu
print(bmi_round)
 #Sprawdzenie BMI w oparciu o przedziały
for(bmi_round in niedowaga) {
  if(bmi == niedowaga) {
    print("Niedowaga")
  }
}
else {
  if (bmi == norma) {
    print("Norma")
  }
}
else if (bmi == nadwaga) {
  print("Nadwaga")
}

I have 3 sequence variables "niedowaga, norma, nadwaga" I calculated BMI index

Now I need to make loop to check computed BMI. "bmi_round" have to check to which sequence it fits - "niedowaga", "norma" and "nadwaga" (first 3 variables) and give output based on computed BMI and sequence

Help folks :)

Sorry for language in comments and in variables name - it's polish ;)


Viewing all articles
Browse latest Browse all 212043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>