c++ fuctions

Discussion in 'Mac Programming' started by chris200x9, Oct 10, 2007.

  1. chris200x9 macrumors 6502a

    Joined:
    Jun 3, 2006
    #1
    hey I have seemed to forgoten how to print functions in c++. Can someone help me? what do I need in main?
     
  2. italiano40 macrumors 65816

    italiano40

    Joined:
    Oct 7, 2007
    Location:
    NY
    #2
    to put to the screen it is
    Code:
    cout<<
    :apple
     
  3. chris200x9 thread starter macrumors 6502a

    Joined:
    Jun 3, 2006
    #3
    yea I know but ok heres my code NOW


    Code:
    
    #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.
     
  4. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #4
    I see in your function definition for Factorial() that it returns an "int".

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

Share This Page