Thread: Simple C++ question

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    4

    Simple C++ question

    I'm new to programming in C++ so I appreciate any help... How can I assign a value of 2.4567 to a enumeration type? ---tia

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You can't. Enumerations are integral types.
    Kurt

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    4
    I need to assign those numbers to enumerations, so their is no way to do it?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You can't assign that value to an enumeration type. Use a const double instead, or provide more information about why you think you need to do that.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    4
    I have to use an enumerated type for the programming assignmnet I'm doing. The way it goes is that I have to incorporate a list of items with associated numbers to go along with it. The numbers are 0.56789 for example.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I have to use an enumerated type for the programming assignmnet I'm doing.
    You have to use an enumerated type because the assignment said to use an enumerated type, or because you think that is the only way to solve the problem?

    >> The way it goes is that I have to incorporate a list of items with associated numbers to go along with it.
    I wouldn't use an enumerated type for that.

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    You could use the enumerations (which are integers) as indexes into an array of doubles. That's about the closest you can get.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    4
    How would you do that?

  9. #9
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    enum something {somethign1, something2, something3};
    
    double array[3] = {2.382, 23.28, 21.2324};
    
    
    array[something1] //when you want to access the number
    is what he means
    My Website
    010000110010101100101011
    Add Color To Your Code!

  10. #10
    Registered User
    Join Date
    Sep 2006
    Location
    UK
    Posts
    13
    Declare the enum and an array of double (or float) values....

    Code:
    enum {
    one,
    two,
    three,
    }
    
    float m_array[20];
    then use the enum values to reference a position in the array

    Code:
    m_array[one]=0.2435;
    m_array[two]=1.5464;
    m_array[2]=0.65464;
    remember that the array is zero based

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