I have made a simple calculator in "Kotlin" using an android studio the problem I got and I don\'t have a way to fix it is how not to repeat the math operations after
If You don't want to add two operators next to each other You have to check if last character is the operator. It will look something like this:
fun appendOnExpresstion(string: String, canClear: Boolean)
{
if (tvResult.text.isNotEmpty())
{
tvExpression.text = ""
}
if (canClear)
{
tvResult.text = ""
tvExpression.append(string)
}
else
{
if (tvExpression.text.lastOrNull() !in arrayOf('+', '-', '*', '/')) // You are adding operator so You have to check if last char is oparetor
{
tvExpression.append(tvResult.text)
tvExpression.append(string)
}
tvResult.text = ""
}
}