unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Programming > C and C++

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2006, 06:51 AM
zero_tolerance zero_tolerance is offline
Senior Member
 
Join Date: Dec 2006
Posts: 289
Default Beginners C++ Lesson 4

By Turv

Lesson 4
-----------------------


Using and making functions


One of the most AWESOME things in C++ is the use of functions, very simplistic and very very useful!

The way that you define a function is much like declairing a variable, they both need a datatype and they both need identifyers.

I will make a simple function for you
Code:
void MyFunc()
{

}
Just like the function main(), it uses braces, just like in main() you can have code inside of the braces, lets do something in it .

Code:
void MyFunc()
{
    cout<<"You called MyFunc"<<endl;
}
You must declair this before you can use it, so we want to use it in main(), you must put that block of code above main(). And inside of main put this.
MyFunc();

This will call the function MyFunc(), which in results displays 'You called MyFunc' on the screen .
Ya, it does seem kind of useless right now, but when you get up into the 1k's lines of code, you will be glad you have functions to help you.
Also, you can use datatypes to create functions, I will make an example for you.
Code:
int IntegerFunc()
{
     return 12*3;
}
If you notice that their is a return in this function, that is because when you call IntegerFunc() it will give you the value that 12*3 returns.
So, you could do this.
cout<<"The result of IntegerFunc() is "<<IntegerFunc()<<endl;

You can also define input datatypes in the function: eg
Code:
int IntegerFunc(int numa, int numb)
{
    return numa * numb;
}
then you can do.
cout<<"The result of IntegerFunc() is "<<IntegerFunc(15, 2)<<endl;

and it should output 30


I hope you enjoyed this lesson

Your project for tomarrow is to make 5 functions and then multiply them together and try and not get an overflow.
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
beginners, lesson

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 04:55 AM.