-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Friday 10 April 2015

Making a simple calculator using switch statement

Asalam o Alikum. I hope you all are fine by the grace of Allah Almighty.
Today I am here with another program that will help you to make a simple arithmetic calculator using switch statement.
Actually switch statement is a good alternative of “if-else-if” or nested if-else. It is very useful in a condition when there are many choices available and only one should be executed.Its syntax is as follows:

Syntax

switch(expression)
{
case 1:
statements;
break;
case 2:
statements;
break;
.
.
default:
statements;
}


Below is the source code of the above mentioned program:

Source code

khgamujtaba,C++,making calculator using switch statement

 Output

khgamujtaba,C++,making calculator using switch statement

Explanation:
               In this program,the result of a single expression is compared with multiple cases.If it matches with a certain case,the statement(s) below that case is executed.After execution,it comes out of the "switch" body due to "break" statement.This is actually the logic of this program.


No comments:

Post a Comment