primtiive calculator in c++

Here is an example of a primitive calculator implemented in C++:

#include <iostream>

int main() {
  int num1, num2;
  char operation;

  std::cout << "Enter the first number: ";
  std::cin >> num1;

  std::cout << "Enter the second number: ";
  std::cin >> num2;

  std::cout << "Enter the operation (+, -, *, /): ";
  std::cin >> operation;

  switch (operation) {
    case '+':
      std::cout << "The result is: " << num1 + num2 << std::endl;
      break;
    case '-':
      std::cout << "The result is: " << num1 - num2 << std::endl;
      break;
    case '*':
      std::cout << "The result is: " << num1 * num2 << std::endl;
      break;
    case '/':
      std::cout << "The result is: " << num1 / num2 << std::endl;
      break;
    default:
      std::cout << "Invalid operation." << std::endl;
      break;
  }

  return 0;
}

Explanation: 1. The code begins by including the necessary header file iostream, which provides input and output functionality. 2. The main() function is the entry point of the program. 3. Inside main(), three variables are declared: num1 and num2 to store the input numbers, and operation to store the desired operation. 4. The user is prompted to enter the first number using std::cout and the input is stored in num1 using std::cin. 5. Similarly, the user is prompted to enter the second number and the operation. 6. A switch statement is used to perform different actions based on the value of operation. 7. If the operation is +, the sum of num1 and num2 is calculated and printed. 8. If the operation is -, the difference between num1 and num2 is calculated and printed. 9. If the operation is *, the product of num1 and num2 is calculated and printed. 10. If the operation is /, the quotient of num1 and num2 is calculated and printed. 11. If the operation does not match any of the cases, an error message is printed. 12. Finally, the main() function returns 0 to indicate successful program execution.

This code allows the user to input two numbers and choose an operation to perform on them, displaying the result accordingly.