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.
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
Comments
Leave a comment