From e14eab57c06a5d949e3ee364a7d40f128a0cc4a8 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Tue, 13 Oct 2020 11:15:35 +0530 Subject: [PATCH 1/2] Added Exponent Operation --- src/main.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.kt b/src/main.kt index 41217e3..5f6583a 100644 --- a/src/main.kt +++ b/src/main.kt @@ -25,6 +25,7 @@ fun main(vararg arg: String){ "*" -> lhs * rhs "/" -> lhs / rhs "%" -> lhs % rhs + "^" -> lhs.pow(rhs) else -> throw IllegalArgumentException("Invalid operator: $operator") } From e89d7b8c59455d6f545fa95f3bf44dbfb84d2a54 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Tue, 13 Oct 2020 11:22:36 +0530 Subject: [PATCH 2/2] Fixed the variable names --- src/main.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.kt b/src/main.kt index 5f6583a..b336449 100644 --- a/src/main.kt +++ b/src/main.kt @@ -15,17 +15,17 @@ fun main(vararg arg: String){ /* Inputs from user */ val operator: String = values[1] - val lhs = values[0].toDoubleOrNull() ?: throw IllegalArgumentException("Invalid input: ${values[0]}") - val rhs = values[2].toDoubleOrNull() ?: throw IllegalArgumentException("Invalid input: ${values[1]}") + val left_operand = values[0].toDoubleOrNull() ?: throw IllegalArgumentException("Invalid input: ${values[0]}") + val right_operand = values[2].toDoubleOrNull() ?: throw IllegalArgumentException("Invalid input: ${values[1]}") /* Checking operator and performing arithmetic operation */ val result = when (operator) { - "+" -> lhs + rhs - "-" -> lhs - rhs - "*" -> lhs * rhs - "/" -> lhs / rhs - "%" -> lhs % rhs - "^" -> lhs.pow(rhs) + "+" -> left_operand + right_operand + "-" -> left_operand - right_operand + "*" -> left_operand * right_operand + "/" -> left_operand / right_operand + "%" -> left_operand % right_operand + "^" -> left_operand.pow(right_operand) else -> throw IllegalArgumentException("Invalid operator: $operator") }