### C++: Program for calculator using functions

#include<iostream>

using namespace std;

using namespace std;

float sum(float, float);

float sub(float, float);

float mul(float, float);

float div(float, float);

float sub(float, float);

float mul(float, float);

float div(float, float);

int main()

{

float x, y, res;

char choice;

cout << "Calculator\n\n";

cout << "Enter two numbers\n";

cin >> x >> y;

cout <<

"Operations \n '+' for addition \n '-' for substraction \n '*' for multiplication \n '/' for division \n";

cin >> choice;

switch (choice)

{

case '+':

res = sum(x, y);

cout << "Sum is :" << res;

break;

case '-':

res = sub(x, y);

cout << "Substraction is:" << res;

break;

case '*':

res = mul(x, y);

cout << "Multiplication is:" << res;

break;

case '/':

res = div(x, y);

cout << "Division is :" << res;

break;

default:

cout << "Enter correct choice";

break;

}

return 0;

}

{

float x, y, res;

char choice;

cout << "Calculator\n\n";

cout << "Enter two numbers\n";

cin >> x >> y;

cout <<

"Operations \n '+' for addition \n '-' for substraction \n '*' for multiplication \n '/' for division \n";

cin >> choice;

switch (choice)

{

case '+':

res = sum(x, y);

cout << "Sum is :" << res;

break;

case '-':

res = sub(x, y);

cout << "Substraction is:" << res;

break;

case '*':

res = mul(x, y);

cout << "Multiplication is:" << res;

break;

case '/':

res = div(x, y);

cout << "Division is :" << res;

break;

default:

cout << "Enter correct choice";

break;

}

return 0;

}

float sum(float a, float b)

{

return a + b;

}

{

return a + b;

}

float sub(float a, float b)

{

return a - b;

}

{

return a - b;

}

float mul(float a, float b)

{

return a * b;

}

{

return a * b;

}

float div(float a, float b)

{

return a / b;

}

{

return a / b;

}

**<Happy Coding>**

## Comments

## Post a Comment