Write a C++ program that performs the four arithmetic operations (addition, subtraction, multiplication and division) on two numbers received from keyboard by prompting. Your program must have specific function for each arithmetic operation.
#include <iostream>
using namespace std;
double executeAddition(double number1, double number2)
{
return number1+number2;
}
double executeSubtraction(double number1, double number2)
{
return number1-number2;
}
double executeMultiplication(double number1, double number2)
{
return number1*number2;
}
double executeDivision(double number1, double number2)
{
return number1/number2;
}
int main()
{
cout << "Enter first number: ";
double number1;
cin >> number1;
cout << "Enter second number: ";
double number2;
cin >> number2;
cout << endl;
cout << number1 << " + " << number2 << " = " << executeAddition(number1, number2) << endl;
cout << number1 << " - " << number2 << " = " << executeSubtraction(number1, number2) << endl;
cout << number1 << " * " << number2 << " = " << executeMultiplication(number1, number2) << endl;
if(number2!=0)
cout << number1 << " / " << number2 << " = " << executeDivision(number1, number2) << endl;
else
cout << "Unable to execute division" << endl;
cout << endl << endl;
return 0;
}
Comments
Leave a comment