Thread: little help

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    176

    little help

    i was wondering waht key work i use so the person can enter a whole word because i am trying to make a mad lib lype game and when i use const tehy can only put in one letter

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try using the string type. You can read about it here.

    http://elvis.rowan.edu/~kunkle/10Feb03-Page1.htm
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    not sure i understand.... is string name the keyword i type? cause i tried that and it didn't work

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Just like the examples on the page I gave you. Make sure you include the appropriate headers first.

    EDIT: Argh, my mistake. It seems that page is a little outdated
    Here is an example.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main( void )
    {
      string name = "Hello World";
    
      cout << name << endl;
    
      return 0;
    }
    Last edited by MrWizard; 07-27-2003 at 10:28 PM.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    errrr i am so confused how do i find out what header file to use? i am using dev-C++


    #include <iostream.h>

    int main()
    {


    int numbertheypick;
    int exit;
    string noun;

    std::cout<<"welcome to the mad lib game! you choose your story number. the story "<<endl;
    std::cout<<"has blanks in it that you have to fill in based on the type of word "<<endl;
    std::cout<<"that will fit in the blank (adjective, noun etc.) and whatever you put "<<endl;
    std::cout<<"in will fill in the blanks in the story, now you wont be able to read "<<endl;
    std::cout<<"the story untill all the blanks are filled in."<<endl;
    std::cout<<" if you dont know what an adjective or noun or whatever is just ask someone "<<endl;
    std::cout<<"or look it up"<<endl;
    std::cout<<" choose a story 1,2,or 3"<<endl;/* all this is is the introductory for the game*/

    std::cin>> numbertheypick;//if they pick 1 2 or 3 the dif. games will be played

    if (numbertheypick == 1)
    std::cout<<"please enter a noun: ";
    cin>> noun;
    std::cout<<"the noun you entered is:"<<noun;
    std::cout<<"bob was walking and suddenly beau walk out and\n";
    std::cout<<"kicked him right in the "<<noun;

    cout<<" press any key and hit enter to quit:";
    cin>>exit;

    return 0;
    }



    is the code i am using course its not fully done but once i fix this it should go quickly

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    1) Use code tags.
    2) Don't use iostream.h. Use 'iostream'.
    3) You need to include 'string'.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    the book i got sucks and i dont know what header file to put in so i can use the string thing

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    The header file you need is <string>
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    thanks a lot i got it to work

Popular pages Recent additions subscribe to a feed