This is a change counter program. The change is counting correctly, but the remainder is not (remChange()). After watching a few videos, and w3schools tutorials, I'm still coming up blank as to why this is. I've added a returnChange at the bottom of each function and was able to get that last 2 functions rounded (from the float). Did I do the floating point wrong in the println? Are my return tags in the wrong place? I'm just trying to get it to work by counting the coins and giving me back the change.
Here is my code: let me know, ill be researching in the meantime.
fun main(args: Array<String>) {
var change = 10.88
getDollars(change)
getQuarters(change)
getDimes(change)
getNickles(change)
}
fun getDollars(change: Double): Double{
val numofdolla = change/(1.00).toFloat();
println(numofdolla.toInt());
val remChange = change - numofdolla * 1.00;
println(remChange)
return change
}
fun getQuarters(change: Double): Double{
val numofqtr = change/(0.25).toFloat();
println(numofqtr.toInt());
val remChange = change - numofqtr * 0.25;
println(remChange)
return change
}
fun getDimes(change: Double): Double{
val numofdime = change/(0.10).toFloat();
println(numofdime.toInt());
val remChange = change - numofdime * 0.10;
println("%.2f".format(remChange))
return change
}
fun getNickles(change: Double): Double{
val numofnick = change/(0.05).toFloat();
println(numofnick.toInt());
val remChange = change - numofnick * 0.05;
println("%.2f".format(remChange))
return change
}
I'm not looking for anyone to write my code, as an explanation would be just perfect.