Advertisement
Guest User

Lösung

a guest
Mar 11th, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.07 KB | None | 0 0
  1. object BMI2 extends App {
  2.  
  3. def isNumber(s: String): Boolean = {
  4.     try {
  5.       s.toDouble
  6.       return true
  7.     } catch {
  8.       case e: Exception => return false
  9.     }
  10.  }
  11.  
  12. var kg = readLine("Please enter your body mass in kg ")
  13. var m = readLine("Please enter your body height in m ")
  14.  
  15.  
  16. if (isNumber(kg)==true && isNumber(m)==true)
  17. {
  18.         var kg1 =kg.toDouble
  19.         var m1 = m.toDouble
  20.  
  21.         if (kg1>=0 && m1>=0)
  22.         {
  23.         var bmi = kg1/(math.pow(m1,2))
  24.        
  25.         if (bmi <18.5)
  26.         {
  27.             print("You are under the ideal weight!")
  28.         }
  29.         else if (bmi <24.9)
  30.         {
  31.             print("You do have normal weight :-)")
  32.         }
  33.         else if (bmi <29.9)
  34.         {
  35.             print("You are above the ideal weight!")
  36.         }
  37.         else if (bmi >30)
  38.         {
  39.             print("Your weight is considerably above the ideal weight!")
  40.         }
  41.        
  42.         } else {
  43.             print("Negative values are not valid!")
  44.         }
  45. }else{
  46.     print("Please only enter numeric values!")
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement