Making of a basic calculator in C++ Part (3/8)

Hello guys, I hope you all are doing good in your life. first of all sorry for not writing articles for almost the last 10 days. I was quite busy but now gear up because, in this part, we are going to design UI of our calculator. Before doing that let’s learn something about functions.

Check this also: Making of a Basic Calculator in C++ Part (1/8)

Check this also: Making of a basic calculator in C++ Part (2/8)


on the ground level, functions are just a combination of many operations. Functions can take certain inputs and outputs the corresponding result. Let’s understand functions with an example:-

This is a function takes three numbers as input and add the first two number and then subtract the third number and return final value.

for ex:- add_subtract_add(8,9,2) = 8+9-2 = 15;

I have just told you a minute fraction of function. you might not appreciate the beauty of function now but incoming articles you will know the real applications of functions.

NOTE:- Try to interpret the syntax of function on your own from the example.


You would have already got an idea of what these statements do. It is simply like “if something is true then perform task_1 and if it is not true to perform task_2”.

clearly, if user input 8 then you are dumb and if any other value is inputted then I am intelligent (:-D). we will practice more if-else statements in coming articles.


If else statements perform the task only one time but while keeps on repeating the task until condition statement is made false. Check out the code below and try to interpret what does it mean (We will learn loops in detail in future).

Now finally let’s check how our interface will look:-

so what we basically are doing is allowing the user to input what he wants to calculate. let’s say if you user inputs 8+9-2/2*2, then, out program should output 15 (check out the sixth-grade mathematics book if you don’t remember what BODMAS rule is). Also if the user only input -8, then, we should user chance to use the calculator again and if user input -1 then, he/she should be able to exit from the program. This might seem complicated for now but it is a simple combination of functions, if-else statements and while loop. GIVE IT A TRY AND I WILL TELL YOU ITS CODE IN NEXT PART. 

Follow Techistaan to get unbiased gadgets reviews and latest tech updates.


Related Articles

Leave a Reply

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

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker