comparing user input to an array element

Discussion in 'C++' started by Brett.h, Dec 29, 2009.

  1. Brett.h

    Brett.h New Member

    Joined:
    Dec 18, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I have been working on this for a while but I can not seem to figure it out, the program compiles but if the user enters a string value that is equal to an element in the array, it doesn't fallow through with the appropriate code, it is equal, but it doesnt think it is.....
    it sounds stupid but.......
    Code:
    ////////////main////////////
        Gen Genesis;
        Genesis.initialize();
        Genesis.input_allcaps(Genesis.get_userinput());
        Genesis.check_userinput();
    //////////////////////////////////////////////////////
    
    
    /////////definitions/////////////////////////////////
    
    string known_statements[known_reference] = {"HELLO"};
    
    string Gen::get_userinput(){
        getline(cin, userinput);   //// I tested it by typing hello for the input /////
        return userinput;
    }
    
    void Gen::input_allcaps(string input){    
        for (int i = 0; i < input.length(); i++){
            userinput[i]=toupper(input[i]);
        }
        cout << userinput;
    }
    
    
    string Gen::check_userinput(){
        for (int cntr = 0; cntr < known_reference; cntr++){
            if(userinput == known_statements[cntr]){
                cout << userinput << " = " << known_statements[cntr] << "n";
            }
        }
        return _response;
    }
    should i be using pointers, if so how?

    any help would be appreciated

    -Brett
     
  2. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    From what you've shown here, I don't see any reason why it shouldn't work. Maybe you should show your real code?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice