Implement the function, double calc (int a, int b, bool& flag); The function che
ID: 3690257 • Letter: I
Question
Implement the function, double calc (int a, int b, bool& flag); The function checks if a and b are larger than zero if so then it sets flag to true, calculates and returns the formula: s = a/squareroot a/b. If a or b is less than or equal to zero it sets flag to false to indicate that the formula cannot be calculated then it returns any value which MUST be ignored by the caller (main()). Test the function with a program that prompts the user to enter two values that represent a and b, calls the functions and prints the appropriate outcomes.Explanation / Answer
#include <iostream>
using namespace std;
int res,res1;
int calc (int a, int b, bool flag)
{
if(a>0 && b>0)
{
res1= a/b;
res=a/(sqrt(res1));
return true;
}
else
{
cout << "The formula cant be solved "
return false;
}
}
int main ()
{
int z;
z = calc(5,3);
cout << "The result is " << z;
}