0

what is wrong with my code ????

Age is provided as input. Child: 0-11 Teens: 12 - 17 years old Adult: 18–64 Seniors: 65+ If the age is negative, you need to output "Invalid Age". Example Input Data: 42 Sample Output Data: Adult fun main(args: Array<String>) { var age = readLine()!!.toInt() if (age<12){ println("Child") } else if(age<18){ println("Teen") } else if(age<65){ println("Adult") } else if(age<68){ println("Senior") } else(age<0){ println("Invalid age") }

19th Sep 2021, 10:16 AM
время Ч
4 Respostas
+ 4
fun main(args: Array<String>) { var age = readLine()!!.toInt() if (age<0){ println("Invalid age") } else if (age<12){ println("Child") } else if(age<18){ println("Teen") } else if(age<65){ println("Adult") } else { println("Senior") } }
19th Sep 2021, 10:41 AM
Simba
Simba - avatar
+ 1
Your condition for seniors is wrong Also in else block you are checking for a condition which is not possible to do. Try this :- else if(age > 68){ println("seniors") } else{ println("invalid age") } Or this :- else if(age > 68){ println("seniors") } else if(age < 0){ println("invalid age") }
19th Sep 2021, 10:41 AM
Niththish
Niththish - avatar
+ 1
thanks
19th Sep 2021, 11:09 AM
время Ч
0
Please include Kotlin in tags☝
19th Sep 2021, 11:06 AM
Ipang