Challenge: Build a Calculator Application

In this lesson, you will learn to build a simple calculator using switch and case statements.

Problem statement #

Write a calculator program that supports arithmetic operations. You are given three variables:

  • operation, which contains the operation to be performed.
  • first, which contains the value of the first number.
  • second, which contains the value of the second number.

The calculator should store the result of the operation in the result variable. The arithmetic operations can be add, subtract, multiply and divide.

Sample input #

operation = "add";
first = 8;
second = 4;

Sample output #

result = 12;

Challenge #

This problem is designed for you to practice, so try to solve it on your own first. If you get stuck, you can always refer to the explanation and solution provided in the next lesson. Good luck!

Get hands-on with 1400+ tech skills courses.