Results 1 to 13 of 13
  1. #1
    That0n3Guy's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    1,137
    Reputation
    13
    Thanks
    271
    My Mood
    Sleepy

    [Guide] Basic C++ Statements etc.

    Info:
    I'm going to show and explain some of the basics of C++ for all the new people that want to learn something. Should my information be incorrect, feel free to correct me.

    1. The Main() Function

    Info:
    This is the function that happens the second your program starts and is USUALLY the last piece of code that runs, also.

    Example: (int comes before main() because it returns an integer value)
    Code:
    int main() 
    {
    cout << "Hello World!";
    system("pause >nul");
    return 0;
    }
    2. Variables

    Info:
    Variables store information for use during your program.

    Types of Variables:
    Integers - Store numbers ONLY.
    Boolean - True or False.
    Char - Stores ONE character
    Float - Integers are great for counting whole numbers, but sometimes we need to store very large numbers, or numbers with a fractional component. A floating point type variable is a variable that can hold a real number, such as 4.0, 2.5, 3.33, or 0.1226. (Credits to Learn C++ - 2.5 — Floating point numbers since I couldn't think of a way to explain it.)
    Strings - Store multiple characters. (Strings require an additional header to be defined before use.)

    3. Basic Output/Input

    Info:
    Basic statements that allow you to write something to the console window or recieve user input for the value of a variable.

    Examples:

    This writes Hello World! to the console window:
    Code:
    cout << "Hello World!";
    This receives user input for the variable x:
    Code:
    int x;
    cout << "What is x?";
    cin << x;


    4. If Statement

    Info:
    Allows you to check if a boolean is true (or even false, in some cases) and if so, do a piece of code.

    Example:
    Code:
    int a = 1;
    if(a = 1) 
    {
    cout << "Integer A is equal to one!";
    }
    5. Loop Statements

    Info:
    Loops allow you to continuously do something until you get the wanted result. (Like +1 until the variable is 10)

    Examples:
    Code:
    while(a=1) 
    {
    a = a+1;
    }
    
    for(int i = 0; i <= 10; i++)
    {
    cout << i << endl;
    }
    If you just try to pop these codes into your compiler, they won't do anything for you without proper use and proper headers being defined. This is just meant to show newer C++ coders some of the fundamentals of C++ to get started with. If you have any suggestions, please post them
    Quotes Hall of Fame

    Quote Originally Posted by martijno0o0 View Post
    ok, i got visual basic 2008 and i got some expirients but i need c++ to make hacks rigth?
    so i need c++ and my question is!?¿? where i dontload it? and is c++ a own program or a update for vb08?
    [IMG]https://i660.photobucke*****m/albums/uu327/EddieTheWin/duff.png[/IMG]

  2. The Following User Says Thank You to That0n3Guy For This Useful Post:

    crushed (12-05-2009)

  3. #2
    t7ancients's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    New York
    Posts
    381
    Reputation
    28
    Thanks
    68
    My Mood
    Twisted
    Quote Originally Posted by That0n3Guy View Post
    Info:
    I'm going to show and explain some of the basics of C++ for all the new people that want to learn something. Should my information be incorrect, feel free to correct me.

    1. The Main() Function

    Info:
    This is the function that happens the second your program starts and is USUALLY the last piece of code that runs, also.

    Example: (int comes before main() because it returns an integer value)
    Code:
    int main() 
    {
    cout << "Hello World!";
    system("pause >nul");
    return 0;
    }
    2. Variables

    Info:
    Variables store information for use during your program.

    Types of Variables:
    Integers - Store numbers ONLY.
    Boolean - True or False.
    Char - Stores ONE character
    Float - Integers are great for counting whole numbers, but sometimes we need to store very large numbers, or numbers with a fractional component. A floating point type variable is a variable that can hold a real number, such as 4.0, 2.5, 3.33, or 0.1226. (Credits to Learn C++ - 2.5 — Floating point numbers since I couldn't think of a way to explain it.)
    Strings - Store multiple characters. (Strings require an additional header to be defined before use.)

    3. Basic Output/Input

    Info:
    Basic statements that allow you to write something to the console window or recieve user input for the value of a variable.

    Examples:

    This writes Hello World! to the console window:
    Code:
    cout << "Hello World!";
    This receives user input for the variable x:
    Code:
    int x;
    cout << "What is x?";
    cin << x;


    4. If Statement

    Info:
    Allows you to check if a boolean is true (or even false, in some cases) and if so, do a piece of code.

    Example:
    Code:
    int a = 1;
    if(a = 1) 
    {
    cout << "Integer A is equal to one!";
    }
    5. Loop Statements

    Info:
    Loops allow you to continuously do something until you get the wanted result. (Like +1 until the variable is 10)

    Examples:
    Code:
    while(a=1) 
    {
    a = a+1;
    }
    
    for(int i = 0; i <= 10; i++)
    {
    cout << i << endl;
    }
    If you just try to pop these codes into your compiler, they won't do anything for you without proper use and proper headers being defined. This is just meant to show newer C++ coders some of the fundamentals of C++ to get started with. If you have any suggestions, please post them
    Ah, this is good, but I noticed cin and cout.
    use cout like this: cout << (variables, expressions, etc. )
    use cin like this: cin >> ( same as above. )
    you had the << and >> mixed up.
    also, at the end of a line of input or output, you should get into the habit of using <<endl or \n
    and can you explain what a double is? They confuse me.
    The character or char data type holds a numerical value from 0 to 256, and each number stands for a character on a keyboard. Let me sift through my source code collection and see if I can find something showing this.
    Last edited by t7ancients; 12-05-2009 at 11:16 AM.

  4. #3
    t7ancients's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    New York
    Posts
    381
    Reputation
    28
    Thanks
    68
    My Mood
    Twisted
    Yay! I found it in this massive folder with like 700 different source files in it...
    Code:
    #include <iostream.h>
    int main()
    {
    using namespace std;
    for (int i = 0; i<256; i++)
    cout << (char) i; 
    getchar(); // waits for a key to be pressed to continue execution of code.
    return 0;
    }

  5. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    a double is named for its size in memory which is a DWORD or double word. An int (integer) is a word) so a double is twice the size and allows for floating point operations. I forget how large it can be, but its a pretty large value.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  6. #5
    Pixipixel_'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    VCExpress.exe || France :D
    Posts
    2,087
    Reputation
    27
    Thanks
    742
    My Mood
    Cool
    Quote Originally Posted by That0n3Guy View Post
    Info:
    I'm going to show and explain some of the basics of C++ for all the new people that want to learn something. Should my information be incorrect, feel free to correct me.

    1. The Main() Function

    Info:
    This is the function that happens the second your program starts and is USUALLY the last piece of code that runs, also.

    Example: (int comes before main() because it returns an integer value)
    Code:
    int main() 
    {
    cout << "Hello World!";
    system("pause >nul");
    return 0;
    }
    2. Variables

    Info:
    Variables store information for use during your program.

    Types of Variables:
    Integers - Store numbers ONLY.
    Boolean - True or False.
    Char - Stores ONE character
    Float - Integers are great for counting whole numbers, but sometimes we need to store very large numbers, or numbers with a fractional component. A floating point type variable is a variable that can hold a real number, such as 4.0, 2.5, 3.33, or 0.1226. (Credits to Learn C++ - 2.5 — Floating point numbers since I couldn't think of a way to explain it.)
    Strings - Store multiple characters. (Strings require an additional header to be defined before use.)

    3. Basic Output/Input

    Info:
    Basic statements that allow you to write something to the console window or recieve user input for the value of a variable.

    Examples:

    This writes Hello World! to the console window:
    Code:
    cout << "Hello World!";
    This receives user input for the variable x:
    Code:
    int x;
    cout << "What is x?";
    cin << x;


    4. If Statement

    Info:
    Allows you to check if a boolean is true (or even false, in some cases) and if so, do a piece of code.

    Example:
    Code:
    int a = 1;
    if(a = 1) 
    {
    cout << "Integer A is equal to one!";
    }
    5. Loop Statements

    Info:
    Loops allow you to continuously do something until you get the wanted result. (Like +1 until the variable is 10)

    Examples:
    Code:
    while(a=1) 
    {
    a = a+1;
    }
    
    for(int i = 0; i <= 10; i++)
    {
    cout << i << endl;
    }
    If you just try to pop these codes into your compiler, they won't do anything for you without proper use and proper headers being defined. This is just meant to show newer C++ coders some of the fundamentals of C++ to get started with. If you have any suggestions, please post them

    These codes are wrong, you have to put "using namespace std;" or "std::cout".

  7. #6
    rwkeith's Avatar
    Join Date
    Jul 2008
    Gender
    male
    Posts
    457
    Reputation
    11
    Thanks
    79
    My Mood
    Angelic
    When you give examples you should include all the header files and enclose in a function, as well as give an example of all the variables. Not to be harsh but this would be hard to understand for a beginner.
    Goals In Life:
    [X] Become an Advanced Member
    [X]Release a tut on mpgh
    [0]Post 300 posts
    [X]Make a working hack
    [X] Learn c++

  8. #7
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by t7ancients View Post
    Ah, this is good, but I noticed cin and cout.
    use cout like this: cout << (variables, expressions, etc. )
    use cin like this: cin >> ( same as above. )
    you had the << and >> mixed up.
    also, at the end of a line of input or output, you should get into the habit of using <<endl or \n
    and can you explain what a double is? They confuse me.
    The character or char data type holds a numerical value from 0 to 256, and each number stands for a character on a keyboard. Let me sift through my source code collection and see if I can find something showing this.
    Character holds value from 0 to 255 (0x00 - 0xFF) . They are basically bytes. Actually 'tis quite surprising that C++ didn't include a byte variable type

  9. #8
    t7ancients's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    New York
    Posts
    381
    Reputation
    28
    Thanks
    68
    My Mood
    Twisted
    pixi, you don't really need to put using napespace for anything, when I leave it out it all works fine. I'm using borland 5.5 compiler so maybe it's just that. I haven't seen anyone else on here that uses borland, it's either dev c++ or msvs.

  10. #9
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    Code:
    while(a=1) 
    {
    a = a+1;
    }
    
    for(int i = 0; i <= 10; i++)
    {
    cout << i << endl;
    }
    shouldn't while(a=1) be while(a==1) because it is checking a value and not changing one.

    and replace a = a+1; by a++; does the same but looks pro...

    a +=1 is possible too

  11. The Following User Says Thank You to lalakijilp For This Useful Post:

    Hell_Demon (12-05-2009)

  12. #10
    t7ancients's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    New York
    Posts
    381
    Reputation
    28
    Thanks
    68
    My Mood
    Twisted
    Quote Originally Posted by lalakijilp View Post
    Code:
    while(a=1) 
    {
    a = a+1;
    }
    
    for(int i = 0; i <= 10; i++)
    {
    cout << i << endl;
    }
    shouldn't while(a=1) be while(a==1) because it is checking a value and not changing one.

    and replace a = a+1; by a++; does the same but looks pro...

    a +=1 is possible too
    an incrementing value has less margin for error, so a++ would be more efficient. looking good is nice and all, but shouldn't practicality hold more priority? and a = 1 as a parameter in a while loop doesn't change the value of a to 1. a = 1 does the EXACT same thing as a == 1 in a loop parameter and takes less to type. you seem like you've confused the syntax and rules of c++ with c#.

  13. #11
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by t7ancients View Post
    and a = 1 as a parameter in a while loop doesn't change the value of a to 1. a = 1 does the EXACT same thing as a == 1 in a loop parameter and takes less to type.
    lalakijilp is right. It changes the value of a to 1, and if that succeeded it continues with the loop.

    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int a=1337;
    	bool bdone=false;
    	while(a=2)
    	{
    		cout<<a<<endl;
    		if(bdone==true)
    		{
    			system("pause");
    			return 1;
    		}
    		bdone=true;
    		Sleep(1);
    	}
    	return 0;
    }
    Last edited by Hell_Demon; 12-05-2009 at 04:40 PM.
    Ah we-a blaze the fyah, make it bun dem!

  14. #12
    crushed's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    My name is Jay. k?
    Posts
    415
    Reputation
    10
    Thanks
    113
    My Mood
    Sneaky
    I say this is absolutely easy. Therefore, if people don't understand this then I don't know what they will.

    I suggest you continue this, and it should be added to the C++ Tut thread under: for beginners as a reference for other people that are just starting C++. It's simple, and to the point.
    Last edited by crushed; 12-05-2009 at 04:48 PM.

  15. #13
    Greg's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    1,806
    Reputation
    51
    Thanks
    86
    My Mood
    Amused
    Perfect for a noob like me.

Similar Threads

  1. Replies: 39
    Last Post: 04-17-2010, 08:32 AM
  2. JokerPlayz's basic guide
    By PyrexxHero® in forum Combat Arms Discussions
    Replies: 13
    Last Post: 11-08-2009, 05:06 PM
  3. Visual Basic 6 portable (1link-5mb) & Noob Guide
    By leonard208 in forum Visual Basic Programming
    Replies: 4
    Last Post: 04-14-2009, 07:58 AM
  4. Visual Basic 6 Complete Guide
    By EndRiT in forum Visual Basic Programming
    Replies: 3
    Last Post: 11-17-2007, 04:42 AM
  5. Idiots Guide To Visual Basic 6
    By nbr1dan in forum WarRock - International Hacks
    Replies: 10
    Last Post: 06-28-2007, 01:07 AM