Exercise 2: Implementing Calculator

Implement a calculator using switch statements.

Problem statement

Write a code that will take the following:

  • Two float type variables named num1 and num2

  • A char type variable called Operator can be assigned one of the following values:

    • +

    • -

    • *

    • /

  • Use switch statements to compute the following on the num1 and num2 variables:

    • Addition

    • Subtraction

    • Multiplication

    • Division

Sample input

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

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