C++20 sections · 1024 units
Open in Course

Problem - Simple Calculator

Four operations

Write a calculator that reads two numbers and an operator character (+, -, *, /). Print the result of applying the operation. You'll use a switch statement with four cases for the operators.

I'll show you how to perform different math operations based on the user's choice. Test with inputs like 10 + 5, 20 - 8, 6 * 7, and 15 / 3. Add a default case to print an error message for invalid operators like % or ^.