I have a recursive function that will repeat the function until the if condition is not met then output an integer. However the function outside this function that requires an integer is receiving a unit. How should I modify the code in order to return an int?
count(r,c,1,0)
def count(r: Int, c: Int, countR: Int, lalaCount: Int): Int = {
if (countR < (r + 1)) count(r,c,countR + 1, lalaCount + countR)
else (lalaCount + c + 1)
}
This is the whole program
object hw1 {
def pascal(c: Int, r: Int): Int = {
count(r,c,1,0)
def count(r: Int, c: Int, countR: Int, lalaCount: Int): Int = {
if (countR < (r + 1)) count(r,c,countR + 1, lalaCount + countR)
else (lalaCount + c + 1)
}
} //On this line eclipse is saying "Multiple markers at this line
//- type mismatch; found : Unit required: Int
//- type mismatch; found : Unit required: Int
pascal(3,4)
}
Unit? Your function is defined as returning anInt, so you're definitely getting anIntback, how did you determine that you're gettingUnitback?