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?
24 Respostas
+ 4
it is now solved. thanks simba and rik wittkopp!
+ 3
Simba š¤£šš¤£
I couldn't see the wood because of the trees
+ 2
Lol it's "Invalid age"
"A" should be lower case in age š
+ 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
+ 1
Abbas Bacha
Please don't spam the Q&A forum
0
it is actually test case 4 and 6
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)
0
now the only test that does not work is #4
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);
}
0
Check your senior value.
You have >65, but senior includes age 65
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);
}
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);
}
0
i just did that and test #4 still not works
0
Can you DM me your code so I can review?
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.
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);
}
0
test case #4 still does not works.
0
Scratching my head here.
We are close!
I going to have a think for a bit
0
ok
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);
}