Thread: i need help deciding the type of variable to use

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    i need help deciding the type of variable to use

    hello and thanks in advance for helping (or even taking a look) I am making a program to calculate various physics problems and at the start of the program i would like the user to specify the are of physics that they're problem is in but how would i set up a variable that is words?

    this is what i have so far:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        variable
        
        cout << "Welcome to the All in One Physics Calculator written by me!\n";
        cout << "to begin type area of physics that your problem is in.\n" << "\n";
        cout << " big 4 \n";
        cout << " projectile motion \n";
        cout << " collisions \n";
        cin >> variable;
        
        
        
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Use an integer.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int variable
        
        cout << "Welcome to the All in One Physics Calculator written by me!\n";
        cout << "to begin type area of physics that your problem is in.\n" << "\n";
        cout << "1) big 4 \n";
        cout << "2) projectile motion \n";
        cout << "3) collisions \n";
        cin >> variable;
        
        
        
        return 0;
    }
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    ok now i need help one more (and hopefully the last) time can a double type variable handle a number with no decimal or does there have to be a .0 at the end of integers?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A double can handle any natural numbers. That is, numbers with no decimal.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Elysia View Post
    A double can handle any natural numbers. That is, numbers with no decimal.
    That's half true. It can handle natural numbers, but it can also handle numbers with decimals. (Just so there's no confusion)
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A member variable that can be of any type.
    By g4j31a5 in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2010, 06:15 AM
  2. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 03:23 PM
  3. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  4. Replies: 6
    Last Post: 07-29-2008, 04:37 AM
  5. "Deciding" in runtime the type of a variable
    By mikahell in forum C++ Programming
    Replies: 28
    Last Post: 07-22-2006, 09:51 AM