### Functions help

Where does nTarget get its a value? I don't know of or see anything that initializes nTarget.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````// //Can someone explain where the function factorial gets a value for nTarget? // // #include #include #include using namespace 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); }``````
look at line 47. nTarget = nValue since it is being used as a parameter with the name of nTaret might I suggest you read up on functions.
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

Ps what is up with your main function?
1) you are not using args.
2) most people if using args name it argc , and argv for count and vectors AFAIK
Last edited on
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.
Topic archived. No new replies allowed.