PDA

View Full Version : c++ fuctions




chris200x9
Oct 10, 2007, 07:02 PM
hey I have seemed to forgoten how to print functions in c++. Can someone help me? what do I need in main?



italiano40
Oct 10, 2007, 07:20 PM
to put to the screen it is
cout<<
:apple

chris200x9
Oct 10, 2007, 07:28 PM
yea I know but ok heres my code NOW




#include <iostream>

using namespace std;
int Factorial( const int num )
{
int t = 1;
int total = 1;
while( t <= num ) {
total = total * t;
t++;
} // end while
cout << total;
return total;
}

int main () {
int number;
int total;
cin >> number;

Factorial (number);



return 0;
}



I get it to print the factorial but my teacher said never to put cout in the function to avoid mistake I'm just having a hard time remembering exactly what to cout so i can have the cout in the main and still ooutput the correct results.


ps. sorry for such a noob-ish question. and thanx very much.

toddburch
Oct 10, 2007, 08:16 PM
I see in your function definition for Factorial() that it returns an "int".

Hummm.... what to do with that int... what to do...?