Reputation: 41
This code is supposed to print the =
symbol. But, when I run the code, it shows nothing … and my code editor says:
Variable 'age' is never used
Variable 'layer' is never used.
I don't understand what is happening here (note: I am a total beginner).
fun main() {
val age = 24
val layers = 5
// printCakeCandles(age)
fun printCakeTop(age: Int) {
repeat(age + 2) {
print("=")
}
println()
}
// printCakeBottom(age, layers)
}
Upvotes: 3
Views: 337
Reputation: 17400
You are never calling the function printCakeTop
, ie the only function that would print something
the age
you define with val age = 24
(line 2) is a different variable than the age
parameter in function printCakeTop(age: int)
(line 5 and 6).
As all function calls, that would use your age
or layer
variables are commented out (//
) , they are marked as unused.
So the following would print something, and also use the age
variable
fun main() {
val age = 24
val layers = 5
// printCakeCandles(age)
fun printCakeTop(age: Int) {
repeat(age + 2) {
print("=")
}
println()
}
printCakeTop(age);
// printCakeBottom(age, layers)
}
Upvotes: 6