## To create a Calculator in C ++

We begin to create a simple exercise of a calculator, where we will use the 4 basic operations of algebra.

We will do it step by step, the first part of the code that we must place are the bookstores of Windows and the bookstores to use the operations of basic entrance and exit:

#include #include

Fact this, we left from our main structure, that is the following one:

int main () \ {return 0;}

Now if we see, for this we need two entrances (numbers to use) to receive data from the keyboard we used the function cin.

We declare the variables and we received them from the keyboard:

int num1, num2 and head of cattle; cout << â€œEnters I number 1: â€?; cin >> num1; cout << â€œenters I number 2: â€?; cin >> num2;

\ n is to give line jump

With this already we asked for both numbers that we will use, now only remains to conduct the operations and to show them in screen:

head of cattle = num1+num2; cout << â€œ\ nLa sum is: â€? << head of cattle;

The exit would be something thus

The sum is: head of cattle

The rest is simple, we only accommodated the code previous to the other operations.

head of cattle = num1 â€“ num2; head of cattle = num1/num2; head of cattle = num1 * num2;

The code in the end, would be of the following way.

#include <stdlib.h> #include <iostream> using namespace STD; int main () \ {int num1, num2, head of cattle; cout << â€œEnters I number 1: â€?; cin >> num1; cout << â€œenters I number 2: â€?; cin >> num2; head of cattle = num1+num2; cout << â€œthe sum ofâ€? << num1 << â€œ+ â€œ<< num2 << â€œis â€œ<< head of cattle; head of cattle = num1-num2; cout << â€œthe subtraction ofâ€? << num1 << â€œ- â€œ<< num2 << â€œis â€œ<< head of cattle; head of cattle = num1/num2; cout << â€œthe division ofâ€? << num1 << â€œbetween â€œ<< num2 << â€œis â€œ<< head of cattle; head of cattle = num1*num2; cout << â€œthe multiplication ofâ€? << num1 << â€œx â€œ<< num2 << â€œis â€œ<< head of cattle; return 0;}

In the console we would have left something thus:

It enters I number 1: 8

it enters I number 2: 7

The sum is: 15

The subtraction is: 1

The division is: 1

The multiplication is: 56

It presses a key to continueâ€¦

**Calculator with menu in c++**

Calculator a little but outpost but nothing difficult.

Â

#include using namespace STD; int main () \ {double n1, n2; int opc; cout << â€œ************************************* \ nâ€? << â€œ* basic Calculator for 2 numbers * \ nâ€? << â€œ************************************* \ nâ€? << endl << endl << endl << â€œEnters the first one I number: â€?; cin >> n1; cout << endl << endl << â€œEnters the second I number: â€?; cin >> n2; system (â€œclsâ€?); cout << â€œ************************************* \ nâ€? << â€œ* basic Calculator for 2 numbers * \ nâ€? << â€œ************************************* \ nâ€? << endl << endl << endl <<â€? That operation wishes to realise? â€œ<< endl << endl << â€œ 1) Sum. \ nâ€? << â€œ 2) Subtraction. \ nâ€? << â€œ 3) Multiplication. \ nâ€? << â€œ 4) Division. \ nâ€? << â€œ*) presses any other I number to leave \ n \ n \ nâ€? <<â€? Enters I number of the option that wishes to realise: â€œ; cin >> opc; switch (opc) \ {marries 1: system (â€œclsâ€?); cout <<â€? \ n \ n the sum of the numbers is: â€œ<< n1+n2 << endl << endl; break; it marries 2: system (â€œclsâ€?); cout <<â€? \ n \ n the subtraction of the numbers is: â€œ<< n1-n2 << endl << endl; break; it marries 3: system (â€œclsâ€?); cout <<â€? \ n \ n the multiplication of the numbers is: â€œ<< n1*n2 << endl << endl; break; it marries 4: system (â€œclsâ€?); cout <<â€? \ n \ n the division of the numbers is: â€œ<< n1/n2 << endl << endl; default: break;} system (â€œIt slows downâ€?); return 0;}

Â