So...
in my
int main () function I have some code
is it possible to make another function like
and show that aswell? or do I have to call it like in php or something?Code:my_name () { blah }
So...
in my
int main () function I have some code
is it possible to make another function like
and show that aswell? or do I have to call it like in php or something?Code:my_name () { blah }
I suggest you read the function tutorial on this site.
Videogame Memories!
A site dedicated to keeping videogame memories alive!
http://www.videogamememories.com/
Share your experiences with us now!
"We will game forever!"
Well typically you declare your functions before int main. Then define them after int main. Then you can use them inside main. Like this:
Also remember that in your functions you can't call for a variable that was initialized in main, unless you pass it to the function.Code:int add(int num_one, int num_two); int main() { cout<< add (4, 5); } int add (int num_one, int num_two) { int result; result = num_one + num_two; return result; }
Inline functions work a little bit different....and you know, there are tutorials on this stuff.
Last edited by IdioticCreation; 01-17-2007 at 08:46 AM.
Code:#include <iostream> using namespace std; int calculate(int a, int b) { int result = (a + b) * 2; return result; } int main() { int num = calculate(10, 20); cout<<num<<endl; cout<<"Hit return to exit."; cin.get(); //to keep the console window open for your viewing pleasure return 0; }
Thanks
Can someone point me to a good tutorial?
C++ is a fairly big language, and you need to get a recent book that is no more than a couple of years old. Is that an option for you?
a veritable feast of tutorials including one on functions
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Possibly, if something Im trying to do doesn't work out, (it should though) then I will be doing this, otherwise I wont7stud C++ is a fairly big language, and you need to get a recent book that is no more than a couple of years old. Is that an option for you?