Calculator Using C++

Introduction:

The calculator is built using c++ in visual studio for the community. The purpose of the project is to create a simple calculator that can complete simple calculations like addition, subtraction, multiplication, and division. The project is an opensource for the students who can modify the code according to their requirements, this project only provides the basic layout of the calculator so that the students can create a scientific calculator with as many functions as they want. 

Operations:

  • Addition
  • Subtraction
  • Division
  • Multiplication

Code:

#include <iostream>
using namespace std;

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

cout << "Enter operator either + or - or * or /: ";
cin >> operation;

cout << "Enter first operand: ";
cin >> num1;

cout << "Enter second operand: ";
cin >> num2;

switch (operation)
{
case '+':
cout << num1 + num2;
break;

case '-':
cout << num1 - num2;
break;

case '*':
cout << num1 * num2;
break;

case '/':
cout << num1 / num2;
break;

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

return 0;
}

No comments:

Post a Comment