Reference no: EM13166806
Create a Boolean function that computes the value of a factorial for values up to including 10. Include comments about how to use the function and describing how it works.
The first parameter is the integer (int) for which you are calculating the factorial.
The second parameter is an integer (int) that must be passed by reference. Use the passed by reference parameter to return the result of the factorial operation.
Before you attempt to compute the factorial make sure that first parameter is a valid number for performing a factorial.
If the first parameter is not a valid number the function must return false.
If the first parameter is a valid number the number must return true and must return the factorial value in the second parameter as described above.
Create a void test function that is to be called from your main function.
In this test function call your factorial function several times using both valid and invalid values for the requested factorial. Be sure to cover all values that are just inside or outside the limits.
Do not use cin to obtain input from the user.
Write several calls to your factorial function. Be sure to capture and check the value of the bool returned by your function in every case.
Use cout to display a failure message on failures (include the invalid attempted factorial).
Use cout to display a success message on success. Include the requested factorial and the computed factorial value.
I only got to bool and I don't get the rest...
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
bool ComputeFactorial(int first, int second);
void FactorialFunction()
{
}
bool ComputeFactorial(int first, int &second)
{
{
if (first > 0 && first <= 10)
{
second = 1;
int n;
for (n = 1; n <= first; n++)
{
second = second * n;
}
return true;
}
else
return false;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
FactorialFunction();
system("pause");
return 0;
}