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") }
4 Réponses
+ 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")
}
}
+ 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")
}
+ 1
thanks
0
Please include Kotlin in tags☝