0

Koitlin sorting out

fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age > 0 && age <= 11 -> "Child"; age > 11 && age <= 17 -> "Teenager"; age > 17 && age <= 64 -> "Adult"; age > 65 -> "Senior"; else -> "Invalid Age"; } println(result); } SORRY ABOUT THE CAPS BUT IPAD WONT TURN THE CAPS OFF. TRYING TO SOLVE THE PROBLEM AND ALL THE CASES BUT 1 AND 4 ARE NOT SOLVED. WHAT CAN I DO?

16th Feb 2021, 5:54 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
24 Answers
+ 4
it is now solved. thanks simba and rik wittkopp!
16th Feb 2021, 9:04 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
+ 3
Simba 🤣😂🤣 I couldn't see the wood because of the trees
16th Feb 2021, 9:02 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Lol it's "Invalid age" "A" should be lower case in age 😅
16th Feb 2021, 9:00 AM
Simba
Simba - avatar
+ 1
Given an age as input, you need to output the age group according to the following categories: Child: 0 - 11 Teen: 12 - 17 Adult: 18 - 64 Senior: 65+ In case the age is negative, you need to output "Invalid age". Sample Input: 42 Sample Output: Adult this is the question
16th Feb 2021, 5:56 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
+ 1
Abbas Bacha Please don't spam the Q&A forum
16th Feb 2021, 6:06 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
it is actually test case 4 and 6
16th Feb 2021, 5:57 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
First thing I noted, the challenge is looking for Teen, you are returning Teenager. If this doesn't fix everything, then look at your age brackets. What if a child is age 11.5, (unlikely as input is int, not double)
16th Feb 2021, 7:57 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
now the only test that does not work is #4
16th Feb 2021, 8:20 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
i modified the age groups too and here is my code: fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age <= 11.9-> "Child"; age > 11 && age <= 17.9-> "Teen"; age > 17 && age <= 64.9 -> "Adult"; age > 65 -> "Senior"; else -> "Invalid Age"; } println(result); }
16th Feb 2021, 8:23 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
Check your senior value. You have >65, but senior includes age 65
16th Feb 2021, 8:24 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
i modified senior fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age <= 11.9-> "Child"; age > 11 && age <= 17.9-> "Teen"; age > 17 && age <= 64.9 -> "Adult"; age > 64 -> "Senior"; else -> "Invalid Age"; } println(result); }
16th Feb 2021, 8:28 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
I checked the input for decimals which won't be accepted because of readLine!!toInt() Your last code has a mistake in the Child line. Try this: fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age >=0 && age < 12 -> "Child"; age >= 12 && age < 18 -> "Teen"; age >= 18 && age < 65 -> "Adult"; age >= 65 -> "Senior"; else -> "Invalid Age"; } println(result); }
16th Feb 2021, 8:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
i just did that and test #4 still not works
16th Feb 2021, 8:40 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
Can you DM me your code so I can review?
16th Feb 2021, 8:42 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age >0 && age < 12 -> "Child"; age >= 12 && age < 18 -> "Teen"; age >= 18 && age < 65 -> "Adult"; age >= 65 -> "Senior"; else -> "Invalid Age"; } println(result); } here is my code.
16th Feb 2021, 8:44 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
Try this: fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age >= 0 && age < 12 -> "Child"; age >= 12 && age < 18 -> "Teen"; age >= 18 && age < 65 -> "Adult"; age >= 65 -> "Senior"; else -> "Invalid Age"; } println(result); }
16th Feb 2021, 8:46 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
test case #4 still does not works.
16th Feb 2021, 8:54 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
Scratching my head here. We are close! I going to have a think for a bit
16th Feb 2021, 8:57 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
ok
16th Feb 2021, 8:57 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
0
Think I found it! Change "Invalid Age" to "Invalid age" fun main(args: Array<String>) { var age = readLine()!!.toInt(); var result = when { age >= 0 && age < 12 -> "Child"; age >= 12 && age < 18 -> "Teen"; age >= 18 && age < 65 -> "Adult"; age >= 65 -> "Senior"; else -> "Invalid age"; } println(result); }
16th Feb 2021, 9:01 AM
Rik Wittkopp
Rik Wittkopp - avatar