Below is a simple Calculator program written in C++ which performs operations like Addition, Subtraction, Multiplication, Division and Swapping.
Note
- The first value as an operator should be a char type and one of (+, -, *, /, s) characters which has the following meanings:
- '+' for addition (num1 + num2)
- '-' for subtraction (num1 - num2)
- '*' for multiplication (num1 * num2)
- '/' for division (num1 / num2)
- 's' for swap
- Program receives another two operands (Num1, Num2) which can be a float or an integer
- The program calculates the appropriate result as per the operation specified and prints the relevant results with related message on console
- Swap operator just exchanges the content of two variables
Calculator Program
#include
#include
using namespace std;
int main()
{
//-------defining variables and initializing them-------------
double num1,num2;
char operation,redo;
cout<<"Simple Calculator"<>operation ;
cout<>num1;
cout<<"2nd num:" ;
cin>>num2;
cout<>redo;
cout<