Challenge 2: Making a Calculator

Test your understanding of the conditional statement concepts covered so far by solving a simple challenge in this lesson.

Problem statement

Write a code which will take:

  • Two variables named $num1 and $num2

  • A string type variable called $Operator which will be passed as input to our given statement

  • The $Operator variable can have any of the following values:

    • +,-,* and /
  • Use the given and when statements to perform:

    • addition
    • subtraction
    • multiplication
    • division

Sample input

$num1 = 5.5
$num2 = 6.5
$Operator = '+'

Sample output

Output = 12

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy