Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object BMI2 extends App {
- def isNumber(s: String): Boolean = {
- try {
- s.toDouble
- return true
- } catch {
- case e: Exception => return false
- }
- }
- var kg = readLine("Please enter your body mass in kg ")
- var m = readLine("Please enter your body height in m ")
- if (isNumber(kg)==true && isNumber(m)==true)
- {
- var kg1 =kg.toDouble
- var m1 = m.toDouble
- if (kg1>=0 && m1>=0)
- {
- var bmi = kg1/(math.pow(m1,2))
- if (bmi <18.5)
- {
- print("You are under the ideal weight!")
- }
- else if (bmi <24.9)
- {
- print("You do have normal weight :-)")
- }
- else if (bmi <29.9)
- {
- print("You are above the ideal weight!")
- }
- else if (bmi >30)
- {
- print("Your weight is considerably above the ideal weight!")
- }
- } else {
- print("Negative values are not valid!")
- }
- }else{
- print("Please only enter numeric values!")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement