Thread: Very simple question

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    11

    Smile Very simple question

    Hi,

    I am currently taking a tutorial about making video games. I have just started C++ and i dont understand what stuff to use for variables or whatever. Here is exactly what i dotn get.

    When i wanna put a variable into my program i dont know what to use. How are all these different.i know all about their ranges and stuff but i just dont get what to use for what

    C++ keyword
    bool
    char
    unsigned char
    short
    unsigned short
    long
    unsigned long
    int
    unsigned int
    float
    double

    I know ur probobly sitting in ur char laughing about my stupid question but cut me soem slack.
    Children in the dark make accidents.

    Accidents in the dark make children.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    int, long, and short (as well as unsigned counterparts) are all integer types - they cannot hold decimal numbers

    char (and unsigned char) is also an integral type, but is generally used when expressing letters

    bool is either 'true' or 'false'

    float, double, and long double are floating-point types - that is, they can hold decimal numbers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    11
    THANKS MAN I LOVE YOU!!!
    Children in the dark make accidents.

    Accidents in the dark make children.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Simple solution:

    1) Use int variables for integer values(whole numbers)

    2) Use double variables for floats(numbers with decimal places)

    3) Use char variables for characters.

    4) Use bool variables if you want to store either true or false.

    and don't worry about the others.

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    11

    Angry

    so then how comw this doesnt work?
    #include <iostream>

    int main (void);


    {
    char x;

    std::cout << "Hi, whats your name?";
    std::cin << x <<;
    std::cout << "Your name is" << x;

    return 0;

    }
    heres the error

    : error C2447: missing function header (old-style formal list?)
    Children in the dark make accidents.

    Accidents in the dark make children.

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    11
    just kidding! i mean this code

    #include <iostream>

    int main (void)

    {

    char x;
    std::cout << "Hi, whats your name?";
    std::cin >> x >>;
    std::cout << "Your name is" << x;

    return 0;

    }
    Children in the dark make accidents.

    Accidents in the dark make children.

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You don't need the extra '>>' operator on cin. Additionally, char only holds one character, to hold a string, you need to use either char*, or the 'std::string' class from the <string> header.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM