Text based game problems

This is a discussion on Text based game problems within the Game Programming forums, part of the General Programming Boards category; I've just started C++ a while ago. I do have a background in Basic, but these two are nothing alike. ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    9

    Text based game problems

    I've just started C++ a while ago. I do have a background in Basic, but these two are nothing alike. The problem I have is with this Text based game. When it gets to the smiliy face, the window shuts off, and nothing happens. I'm sure it's just a simple problem but I can't find it. Please help if you can.

    And if anyone knows how to use the Goto/Label function, please tell me!

    Code:
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    
    using namespace std;
    
    int main()              // This is the beginning, and choose species.
    {
        char species[5];
        int age;
        char name[25];
        char backpack[100];
        
        
        cout<<" Greetings, friend, and Welcome, to...\n";
        cin.get();
        cout<<"    The Lord of The Rings RPG (V1.0)\n";
        cout<<" You will be playing the part of one of the many species\n";
        cout<<" of Middle Earth, on an epic quest to save the world, and\n";
        cout<<" destroy the one ring. To begin, please choose your species...\n";
        cin.get();
        cout<<" \n";
        cout<<" A balanced Human.\n";
        cout<<" A powerful fierce, yet short Dwarf.\n";
        cout<<" A stealthy, dead eye Elf.\n";
        cin.getline ( species, 5);
        cin.ignore();
        
        if ( strcmp (species, "Human") == 0){
           cout<<" Human.\n";
    }      
        else if (strcmp (species, "Dwarf") == 0){
           cout<<" Dwarf.\n";
    }       
        else if (strcmp (species, "Elf") == 0){
           cout<<" Elf.\n";
    }      
        else {
           cout<<"Restart, and choose a real species!\n";
    }         
                     
        cout<<" What is your name(under 25 letters)?\n"; //This is the name.
        cin.getline ( name, 25);
        
    cin.get();
        cout<<" And last, what is your age?\n";  //This is the age.
        cin>> age;
       
        cout<<" Wow, a "<<age<<" year old "<<species<< " named "<<name<<". Now I've\n";
        
        cout<<" Seen everything! Anyway...\n";
        cout<<" \n";            
        cout<<" You begin your quest, in your small village. You have little armour,\n";
        cout<<" except for the clothes on you back, and your sword is of crappy wood.\n";
        cin.get();
    }

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    9

    Crap

    I have the wierdest feeling I didn't put the smiliy faces in.

    Well, they are supposed to be at the beginning of the "if" statments. Sorry.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you need to allocate room for the null terminator in your c-string.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    9
    Not to sound like a noob, but how exactly do I do that. Sorry for all the trouble.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    char name[25];

    should be

    char name[25 + 1]; //1 more byte for '\0'

    edit:

    just noticed but

    char species[5];

    should be

    char species[6];

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    9
    How the crap could I screw up so bad? Thanks a ton.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text based game
    By beene in forum Game Programming
    Replies: 10
    Last Post: 05-12-2008, 08:52 PM
  2. How to make a UI in C++ for a text based game.
    By TylerMoyer in forum Game Programming
    Replies: 12
    Last Post: 07-20-2007, 08:29 PM
  3. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 07:39 AM
  4. Problems putting a text file into a matrix.
    By warny_maelstrom in forum C Programming
    Replies: 15
    Last Post: 01-22-2004, 06:33 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM

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