Answer to Question #204883 in C++ for Syasya

Question #204883

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 :

  • User input (firstnumber, secondnumber) -enter by user
  • User Result in (Addition, Minus, Multiply, Divide, Average)
1
Expert's answer
2021-06-09T04:24:24-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog