In: Computer Science
Write code to define a function named mymath. The function has
three arguments in the following order: Boolean, Integer, and
Integer. It returns an Integer.
The function will return a value as follows:
1. If the Boolean variable is True, the function returns the sum
of the two integers.
2. If the Boolean is False, then the function returns the value of
the first integer - the value of the second Integer.
The answer to this question is as follows:
The code is as follows:
#include <iostream>
using namespace std;
//Decalring the function mymath that takes three parameters
int mymath(bool value,int a,int b)
{
if(value==true)
{
//if the boolean value is true return sum
return a+b;
}
//otherwise return first value - second value
else
{
return a-b;
}
}
int main() {
int x=10;
int y=25;
bool val=true;
//calling the function and printg the output
cout<<"The ouput is "<<mymath(val,x,y);
}
The input and output is provided in the screenshot below: