I am taking Google's Kotlin Basics course for Android development. I am now at a exercise that wants me to create a function that calculates the sum of whatever number two variables hold (there are three variables, which hold the numbers 10, 5, and 8 for this particular exercise.) and then allow println to print out a string that goes like: "$firstNumber + $secondNumber = $result".
Trouble is, those numbers are assigned to variables defined in another function, which after some trial and error I discovered I can't call into another function (Which would make the need for a second function obsolete anyway, I guess).
I do not wish for the straight awnser to my exercise of course, just a hint as to what I can do to get those numbers in the add() function, sum them up, and then somehow get the "val result" variable to get the sum and print it out.
This is the one thing I tried:
just straight up type "var sum = firstNumber + secondNumber", only to remember the course hasn't gone over declaring variables that can be used across functions (if such thing is even possible in Kotlin), and even then, how do I get "val result" to hold the same number as "var sum"? I don't know how to do that either (the course hasn't gone over something like that yet either).
I then executed it anyway, got some errors as expected, the most prominent of which was the one that of course told me I cannot just use the same variable defined in main() and expect the other function to know what the heck I was talking about.
Now I thought of a whole lot of other solutions, none of which got around the problem of not being able to transfer a number/Integer in one function to another without being able to define something like a global variable or whatever.