A Primitive Calculator
A Primitive Calculator
Tags: Math Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Implement a primitive calculator that accepts some operation code
with two parameters operand1
and operand2
. This problem is designed to help you practice using and calling custom functions
. The helper functions should accept two parameters and return the operation result.
Constraints:
- The input will be a
string
opcode. - The operands will be two
integers
- The main method calculator should
return an integer
representing the result of the requested operation. - You should use the provided helper functions.
Example:
- Input:
"add", 1, 2
- Output:
3
Test Case | Input | Expected Output |
---|---|---|
1 | "add", 1, 2 | 3 |
2 | "subtract", 1, 2 | -1 |
3 | "multiply", 1, 2 | 2 |
4 | "divide", 1, 2 | 0.5 |
Leave a Comment
Please login to leave a comment.