If we want to create a simple calculator in C++ which is able to operate simple arithmetic operations like addition, subtraction, multiplication and division. again here is an example of applications of arithmetic and conditional operators in C++. Here is our simple Calculator’s C++ code.
lets look at it.
[cpp] //Creating a simple calculator in C++
using namespace std;
float num1,num2; //numbers "num1"and"num2"
cout<<"enter the statement:n";
//asking the user for statement
if (op== ‘+’) //condition for addition
if (op==’-‘) //condition for subtraction
if (op==’*’)//condition for multiplication
if (op==’/’) //condition for division
First of all we took two variables of datatype “float” and a variable of type “char”. then we asked the user to enter the the statement he want to calculate.e.g 3+4, after this the program searched for the conditional structure true for the variable “op”, if we want to add the two numbers, the first conditional structure is called,similarly second condition for subtraction and so on.and at the end we got our result just like a calculator. And that was our simple arithmetic calculator in C++.