Answer to Question #266686 in C++ for manci

Question #266686

Write a function CalculateVal that takes two integer parameters and returns the first parameter minus twice the second parameter. 

Ex: CalculateVal(4, 6) returns -8.


1
Expert's answer
2021-11-16T00:47:20-0500


SOLUTION TO THE ABOVE QUESTION


SOLUTION CODE


#include<iostream>




using namespace std;


//define our function CalculateVal


int CalculateVal(int p1, int p2)
{
	return p1-(p2*2);
}


int main()


{
//lets prompt the user to enter two integers and call our function
cout<<"\nINPUT:"<<endl;
int parameter_1, parameter_2;
cout<<"\nEnter the first parameter: ";
cin>>parameter_1;
cout<<"\nEnter the second parameter: ";
cin>>parameter_2;


//call the function
cout<<"\nThe output of the function is: "<<CalculateVal(parameter_1,parameter_2)<<endl;


  return 0;


}


SAMPLE PROGRAM OUTPUT






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
APPROVED BY CLIENTS