Login Register
MoHH2 Legendz

Legends of Medal of honor:Heores 2.. Never forgotten RiP in piece


    You are not connected. Please login or register

    View previous topic View next topic Go down  Message [Page 1 of 1]

    Post: #1Wed Aug 22, 2012 11:20 am

    ordo ab chao

    ordo ab chao

    Member


    Variables are data storage in C++, and there are around 8 different types(I think). I will only show the most basic 3 types, because I dont want to open up Code::Blocks to tell the fourth one correctly.
    Variable type #1[Int(integer variable)]
    The variable type int is what you use when you want a program to hold a number value, for example
    Code:
    #includes <iostream>
    using namespace std;

    int main()
    {
      int x;
      cout <<"enter a number" << endl;
      cin >> x;
      system("PAUSE");
      return 0;
    }

    Variable type #2[float]=
    The variable type float is used when you want to have a number with decimal places, for example:
    Code:
    #includes <iostream>
    using namespace std;

    int main()
    {
      float x;
      x = 1.235486;
      cout << "this is x " << x << endl;
      system("PAUSE");
      return 0;
    }

    Variable type #3[char(character variable) =
    the variable type char is used when you want to hold letter values, and you declare the length like this:
    Code:
    #includes <iostream>
    using namespace std;

    int main()
    {
      char x[128];//changing the number in the brackets changes the length
      cout << "enter your name. " ;
      cin >> x;
      system("PAUSE");
      return 0;
    }

    those are the three most basic types of variables in c++, they should be sufficient for most of your coding needs, in the next tutorial I will post up some starting code for a text based game, and show you how to add in music, along with posting up my own text based game which I sadly deleted the Code::Blocks project so I dont have it's source code anymore Crying or Very sad . anyways, have a nice day.


    Post: #2Thu Oct 17, 2013 2:46 pm

    emu

    emu

    Newbie
    Newbie


    Elaboration on a few data types:

    (int) Integer = are whole numbers and negative numbers

    (float/decimal) Decimal = are real numbers, whole numbers, and negative numbers. Floats are decimals too but just smaller decimals, and decimals are from a very wide range. Best to use decimal over float for space purposes.

    (string) String = hold line of text

    (char) Character = holds single characters such as 'A' or 'a'

    (bool) Boolean = true(1) or false(0), uses 1's and 0's to represent true or false. Binary consists of  two digits 1 and 0. Computer's run off of binary.


    View previous topic View next topic Back to top  Message [Page 1 of 1]

    Permissions in this forum:
    You cannot reply to topics in this forum