//
//Can someone explain where the function factorial gets a value for nTarget?
//
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
// Return the factorial of the argument
// provided. return a 1 for invalid arguments
// such as negative numbers
int factorial (int nTarget)
{
//set up an accumulator that is initialized to one
int nAccumulator = 1;
for (int nValue = 1; nValue <= nTarget; nValue++)
{
nAccumulator*= nValue;
}
return nAccumulator;
}
int main(int nNumberofArgs, char* pszArgs[])
{
cout << "This program calculates"
<< " factorials of user inputs.\n"
<< "Enter a negative number to exit" << endl;
//stay in a loop input for the user until he enters a negative number.
for (;;)
{
//enter a number to calculate the factorial of
int nValue;
cout << "Enter a number: ";
cin >> nValue;
//exit if number is negative
if (nValue< 0)
{
break;
}
int nFactorial = factorial (nValue);
cout << nValue << " factorial is "
<< nFactorial << endl;
}
system ("PAUSE");
return(0);
}
Thank you that helped I was thinking that had something to do with it, but the reference really helped thank you. The main function is made out of magic and rainbows to me, I don't question it.