COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Selections/Decisions MinValue.java PrintingService.java QuadraticEquation.java PayrollWithDecision.java MultiSelection.java CalculatorWithSwitch.java GradeBookWithSwitch.java StringComparison.java



CalculatorWithSwitch Program


Description

This program prompts the user to input two operands and a operator, then uses a switch structure to evaluate the operator to determine which operation to perform (+, -, *, or /), and calculates the result based on the operator.

Associated Concepts:

Switch structure

Algorithm:

Input two operands and one operator from the keyboard

Use switch to evaluate the operator

    For '+' operator, perform addition on two operands

    For '-' operator, perform subtraction on two operands

    For '*' operator, perform multiplication on two operands

    For '/' operator, perform division on two operands

    For any other operator, print an error message

    Print the result

Source Code



Sample Run



Video