How to use enumerators to store input

This is a discussion on How to use enumerators to store input within the C++ Programming forums, part of the General Programming Boards category; ok i bought beginning C++ game programming about a week ago and i've read the first 2 chapters and i ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    26

    How to use enumerators to store input

    ok i bought beginning C++ game programming about a week ago and i've read the first 2 chapters and i get everything exept this one exercise where your supposed to take the "Menu Chooser" program (a program which asks the user what difficulty he wants to play at and then uses switch case to determine what to say) and make it work with enumerations. well my problem is that i can't find a way to store input into the enumerator and it's driving me mad. if you could help me with this it would relieve me from some serious stress.

    thanks, Rubiks14

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    enum Choices {SUPEREASY, EASY, NORMAL, DIFFICULT, HARD, VERYHARD, OMGJUSTKILLMENOW};
    
    // .................
    
    void somefunc(void)
    {
      cout<<"You feeling lucky punk? ";
      Choices choice;
      cin >> choice;  // as an INTEGER
    }
    If you want to do string input then you have to do some fancy stuff

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    26
    i tried something almost like that and i kept getting an error when i ran my code but now for some retarded reason it works . thanks for the response

    EDIT: wait nevermind i know what it is, it doesn't work still. here is my code. do realise that this code is mine but is almost the same concept as the one in the book.

    Code:
    #include <iostream>
    
    using namespace std;
    
    enum difficulty {Easy = 1, Medium = 2, Hard = 3};
    
    int main()
    {
    
    difficulty myDifficulty;
        
        cout << "1 - Easy\n";
        cout << "2 - Medium\n";
        cout << "3 - Hard\n";
        cout << "Make your choice. ";
        cin >> myDifficulty;
        cin.ignore();
        
        if (myDifficulty == Easy){
           cout << "You suck";
        }
        else if (myDifficulty == Medium){
           cout << "Ok, i guess you don't suck that bad";
        }
        else if (myDifficulty == Hard){
           cout << "Takin a chance eh";
        }
        cin.get();
    }
    and here is the error i get: no match for 'operator>> 'in 'std::cin >> myDifficulty'
    Last edited by Rubiks14; 10-16-2005 at 09:42 PM.

  4. #4
    1479
    Join Date
    Aug 2003
    Posts
    253
    I added the parts in bold text and it runs fine.

    Code:
    #include <iostream>
    
    using namespace std;
    
    enum difficulty {Easy = 1, Medium = 2, Hard = 3};
    
    int main()
    {
    
    difficulty myDifficulty;
    int x;
    x = myDifficulty;
        
        cout << "1 - Easy\n";
        cout << "2 - Medium\n";
        cout << "3 - Hard\n";
        cout << "Make your choice. ";
        cin >>  x;
        cin.ignore();
        
        if (x == Easy){
           cout << "You suck";
        }
        else if (x == Medium){
           cout << "Ok, i guess you don't suck that bad";
        }
        else if (x == Hard){
           cout << "Takin a chance eh";
        }
        cin.get();
    }
    I am sure there is a better way to do this though...
    Knowledge is power and I want it all

    -0RealityFusion0-

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    26
    thank you, that solved the problem of the error but sadly there still is one. no matter what i type in it says "Ok, i guess you don't suck that bad"

    EDIT: sry didn't add the x in the if statements
    Last edited by Rubiks14; 10-16-2005 at 09:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21