Prepare 5 mathematical functions (add , minus , multiply , divison , average) with two passing parameters and a return value for two numbers entered by the user. Display the result in following format.
Must include :
#include <iostream>
using namespace std;
float add(float firstnumber,float secondnumber);
float minus(float firstnumber,float secondnumber);
float multiply(float firstnumber,float secondnumber);
float divison(float firstnumber,float secondnumber);
float average(float firstnumber,float secondnumber);
int main (){
float firstnumber;
float secondnumber;
cout<<"Enter the first number: ";
cin>>firstnumber;
cout<<"Enter the second number: ";
cin>>secondnumber;
//Addition, Minus, Multiply, Divide, Average
cout<<"\nAddition: "<<add(firstnumber,secondnumber)<<"\n";
cout<<"Minus: "<<minus(firstnumber,secondnumber)<<"\n";
cout<<"Multiply: "<<multiply(firstnumber,secondnumber)<<"\n";
cout<<"Divide: "<<divison(firstnumber,secondnumber)<<"\n";
cout<<"Average: "<<average(firstnumber,secondnumber)<<"\n";
system("pause");
return 0;
}
float add(float firstnumber,float secondnumber){
return firstnumber+secondnumber;
}
float minus(float firstnumber,float secondnumber){
return firstnumber-secondnumber;
}
float multiply(float firstnumber,float secondnumber){
return firstnumber*secondnumber;
}
float divison(float firstnumber,float secondnumber){
return firstnumber/secondnumber;
}
float average(float firstnumber,float secondnumber){
return add(firstnumber,secondnumber)/2.0;
}
Comments
Leave a comment