Write a C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch case

C++ Program to Make a Simple Calculator

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Make a Simple Calculator
C++ Program to Make a Simple Calculator

Write a C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch….case

PROGRAM:Write a C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch….case

/* Write a C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch....case */

# include <iostream>
using namespace std;

int main() {

char op;
float num1, num2;

cout << “Enter operator: +, -, *, /: “;
cin >> op;

cout << “Enter two operands: “;
cin >> num1 >> num2;

switch(op) {

case ‘+’:
cout << num1 << ” + ” << num2 << ” = ” << num1 + num2;
break;

case ‘-‘:
cout << num1 << ” – ” << num2 << ” = ” << num1 – num2;
break;

case ‘*’:
cout << num1 << ” * ” << num2 << ” = ” << num1 * num2;
break;

case ‘/’:
cout << num1 << ” / ” << num2 << ” = ” << num1 / num2;
break;

default:
// If the operator is other than +, -, * or /, error message is shown
cout << “Error! operator is not correct”;
break;
}

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *