Results 1 to 9 of 9
  1. #1
    Tightmarrow's Avatar
    Join Date
    Dec 2016
    Gender
    male
    Posts
    40
    Reputation
    31
    Thanks
    21

    C++ For Beginners

    A few thing I have to say before the tutorial begins:

    - I will try to use at least 2 different ways to do a code.
    - I will avoid using "using namespace std" as more complicated stuff will make using this impossible.
    - Make sure to read explanations, being a leecher won't help you.
    - Write these codes while you read, play around a bit with them too, that's how you learn.


    Simple Calculations:

    So the first thing you need to learn is to make some easy calculations such as addition, multiplication, division, square root, etc. So we will start with some basic includes:

    Code:
    #include <iostream>
    #include <string.h>
    So all of the calculation stuff (and much more, obviously), exist in the iostream library.
    The string library will basically allow us to define strings, which is basically any form of text.
    i.e.: "d1f2432wt23wg%##FRTT##t2gw34" is a string.

    Code:
    int main(){
    Here the code basically starts. We are doing calculations, remember, so we will have to say it's an int (integer a.k.a. number), we will find out about more on this in another tutorial.

    Code:
    int a, b;
    Here we're defining some integers that will be given a value by you and will be made calculations with. You can name them whatever you want, but remember to put a comma (",") between them and obviously a semicolon (";") at the end.

    Code:
    std::cout << "Give the integers their values: ";
    Remember, we did not add the std at the beginning of our program so we'll have to write it in the code, like here, for cout. Cout basically means that it will print a text on the screen, hence the name c + out. We are printing the text "Give the integers their values: " which has to be between quotation marks(").

    Code:
    std::cin >> a << ", " >> b;
    Now you are giving the integers a and b a value and because they are integers, that value will be a number.
    Like, I said, I will give you an alternative to cin, though I don't know if it actually matters but here you go:
     
    getline(std::cin, a); which means std::cin >> a;


    >> - Used by cin for giving a value to that integer (can be a string too, but you'll see that later) and also used by cout if you want to print that integer's value (after you gave it one with cin of course, but you can also do that without cin: i.e.: int a = 4;).

    << - Used for printing text by cout mainly.

    The output until now will be (what you will see after you compile this program):
     

    Code:
    Give the integers their values:
    Let's say you give a the value 4, so you type 4 and press enter, you will see:

    Code:
    Give the integers their values: 4,
    So now you'll just give b the value and move on.


    Before we move on, I want to tell you about std::endl, which is exactly what it says, end line, it ends the current line and moves to the other. For example:

    Code:
    std::cout << "line1" << std::endl;
    std::cout << "line2";
    The output will be:

    Code:
    line1
    line2
    You can also use "\n" for this, as in:

    Code:
    std::cout << "line1\nline2";
    Which will also output:

    Code:
    line1
    line2
    So now you want to do some actual calculations, let's do all at once.

    So let's say:

    a = 4.
    b = 6.



    Code:
    std::cout << a + b << std::endl;
    This will mean 4 + 6 which is 10.

    Code:
    std::cout << a - b << std::endl;
    This will mean 4 - 6 which is -2.

    Code:
    std::cout << a * b << std::endl;
    This will mean 4 x 6 which is 24.

    Code:
    std::cout << a / b << std::endl;
    This will mean 4 : 6 which is 0,(6).

    Code:
    std::cout << sqrt(pow(a,2)) << std::endl;
    Because a's value was set to 4, this code means √4²

    Code:
    std::cout << pow(b,4) << std::endl;
    The value of b is 6, this code means 6⁴

    Checks:

    So you have to learn about if and else statements, which are basically exactly what their name is:

    if(a<0) means if a<0 is true

    if(!a<0) means if a<0 is false

    After this we will open the brackets and we say what happens if that argument is true or false.

    else(a>0) means that else the argument that a<0 (if(a<0)) we made before is false, for example, !a<0 so a is not smaller than 0, we come with an else expression and say else that isn't smaller than 0, but is bigger than 0, it does something else.

    For example we have:

    Code:
    int a = 5;
    std::cout << "Give 'a' a value: ";
    std::cin >> a;
    We want to check if the value of 'a' that was entered is actually an integer (number). We can do:

    Code:
    if(std::cin.fail()){
    return 0;
    }
    Which basically checks if the cin of a failed (because of course if you enter 'afg43g34' where you should've entered a number, that makes no sense, so in the case if fails, it returns 0 (closes the program).

    There are a bunch of things you can use with if/else but it's obviously no one learns them all, if you need something you google it and you'll find it, you don't need to learn anything you basically need to learn how to learn, though there are some things you will need to know:

     
    && means 'and'
    || means 'or'
    != means 'not equal'
    == means 'equal'



    That's all for this tutorial, I had to make it short as I don't have much time right now, in the next one (hopefully) will be about:

    - for
    - while
    - define
    - typedef
    - pragma
    - vector

  2. The Following 3 Users Say Thank You to Tightmarrow For This Useful Post:

    adnaan99 (05-24-2017),moneymademe (05-23-2017),VOSSWATER (01-05-2017)

  3. #2
    Fliest_aladdin's Avatar
    Join Date
    Apr 2012
    Gender
    male
    Location
    YB house
    Posts
    2,708
    Reputation
    31
    Thanks
    288
    My Mood
    Breezy
    what about arrays and pointers
    Add me on IM
    Add me on IM




    If you would like to Vouch For me
    Tutorial on HOW to SE FitBit

  4. #3
    ASERHaerheadrherherh's Avatar
    Join Date
    Mar 2014
    Gender
    male
    Location
    California
    Posts
    716
    Reputation
    23
    Thanks
    93
    My Mood
    Angelic
    Quote Originally Posted by Fliest_aladdin View Post
    what about arrays and pointers
    I would like to see this too; arrays are very important, but to me, not really for hack purposes. Much more useful for general purpose coding, though, if you want to store variables such as accounts and stuff without making a thousand different variables.

  5. #4
    Fliest_aladdin's Avatar
    Join Date
    Apr 2012
    Gender
    male
    Location
    YB house
    Posts
    2,708
    Reputation
    31
    Thanks
    288
    My Mood
    Breezy
    Quote Originally Posted by MrSurvivor View Post
    I would like to see this too; arrays are very important, but to me, not really for hack purposes. Much more useful for general purpose coding, though, if you want to store variables such as accounts and stuff without making a thousand different variables.
    yea, i'm taking 3 quarters of coding and my last quarter they were talking about pointers and array and they make no sens
    Add me on IM
    Add me on IM




    If you would like to Vouch For me
    Tutorial on HOW to SE FitBit

  6. #5
    OGRick's Avatar
    Join Date
    Dec 2016
    Gender
    female
    Posts
    23
    Reputation
    10
    Thanks
    1
    Nice thread, however a lot of docs exist on this anyway.

  7. #6
    ASERHaerheadrherherh's Avatar
    Join Date
    Mar 2014
    Gender
    male
    Location
    California
    Posts
    716
    Reputation
    23
    Thanks
    93
    My Mood
    Angelic
    Quote Originally Posted by OGRick View Post
    Nice thread, however a lot of docs exist on this anyway.
    Better than nothing XD
    There are quite a few guides on this online, though; I noticed that the syntax is "similar" to Java...

  8. #7
    andrewashraf99's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    16
    Reputation
    10
    Thanks
    1
    thanks mate....

  9. #8
    Rpal's Avatar
    Join Date
    Nov 2016
    Gender
    male
    Posts
    10
    Reputation
    10
    Thanks
    1
    great thanks bro

  10. #9
    quality.lifestyle's Avatar
    Join Date
    Sep 2017
    Gender
    male
    Posts
    78
    Reputation
    41
    Thanks
    8
    Nicd one, needed it. Thanks

Similar Threads

  1. WPE for Beginners (Flash Games)
    By Zededarian in forum Game Hacking Tutorials
    Replies: 9
    Last Post: 03-19-2016, 11:59 AM
  2. best c++ tutorial for beginners!
    By WacKer in forum C++/C Programming
    Replies: 31
    Last Post: 12-05-2009, 06:30 AM
  3. Best guns for Beginners and Experts
    By Noescapingus in forum Combat Arms Hacks & Cheats
    Replies: 10
    Last Post: 12-13-2008, 10:29 PM
  4. Great tutorial for beginners
    By kalwarbo in forum Visual Basic Programming
    Replies: 4
    Last Post: 07-19-2008, 07:11 AM
  5. good C++ tutorial for beginner?
    By MaskedFox in forum C++/C Programming
    Replies: 11
    Last Post: 12-05-2007, 04:34 PM