Jump to content
  • Advertisement
Sign in to follow this  
Sam Robinson

So I made this... Help xD

This topic is 2145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone please show me a way to debug this. My compiler keeps saying that characterName, characterRace and characterClass are undefined functions. I want these to be variables to store the character's information.
 
// Adventure Game
 
#import <iostream>
#import <string>
 
using namespace std;
 
int main ()
{
    
    cout << "\tWelcome to The Generic Adventure Game!\n\n";
    cout << "Please create your character\n\n";
    
    // Character Customization
    cout << "Name: ";
    cin >> characterName;
    cout << "\n\n";
        
    cout << "Available races...\n";
    cout << "Dwarf, Human, Orc\n\n";
    cout << "Race: ";
    cin >> characterRace;
    cout << "\n\n";
        
    cout << "Available classes...\n";
    cout << "Paladin, Wizard, Warrior\n\n";
    cout << "Class: ";
    cin >> characterClass;
    cout << "\n\n";
        
    if (characterName == False)
       cout << "Name is invalid. One word names only.";
       continue;
        
    if (characterRace != "Dwarf" || "Human" || "Orc")
       cout << "Race is invalid. Remember the races are Dwarf, Human and Orc.";
       continue;
        
    if (characterClass != "Paladin" || "Wizard" || "Warrior")
       cout << "Class is invalid. Remember the classes are Paladin, Wizard and Warrior";
         continue;
        
    if (characterName == True && characterRace == "Dwarf" || "Human" || "Orc"
    && characterClass == "Paladin" || "Wizard" || "Warrior")
       break;
}

Share this post


Link to post
Share on other sites
Advertisement

You need to declare variables before you use them.

 

A quick fix of your code to get it compiling for you:

// Adventure Game

#include <iostream>
#include <string>

using namespace std;

int main ()
{
    std::string characterName;
    std::string characterRace;
    std::string characterClass;

    cout << "\tWelcome to The Generic Adventure Game!\n\n";
    cout << "Please create your character\n\n";

    // Character Customization
    cout << "Name: ";
    cin >> characterName;
    cout << "\n\n";

    cout << "Available races...\n";
    cout << "Dwarf, Human, Orc\n\n";
    cout << "Race: ";
    cin >> characterRace;
    cout << "\n\n";

    cout << "Available classes...\n";
    cout << "Paladin, Wizard, Warrior\n\n";
    cout << "Class: ";
    cin >> characterClass;
    cout << "\n\n";

    if (characterName.find(' ') != string::npos) {
        cout << "Name is invalid. One word names only.";
        return -1;
    }

    if (characterRace != "Dwarf" && characterRace != "Human" && characterRace != "Orc") {
        cout << "Race is invalid. Remember the races are Dwarf, Human and Orc.";
        return -1;
    }

    if (characterClass != "Paladin" && characterClass != "Wizard" && characterClass != "Warrior") {
        cout << "Class is invalid. Remember the classes are Paladin, Wizard and Warrior";
        return -1;
    }

    if (!characterName.empty() &&
        (characterRace == "Dwarf" ||
        characterRace == "Human" ||
        characterRace == "Orc") &&
        (characterClass == "Paladin" ||
        characterClass == "Wizard" ||
        characterClass == "Warrior"))
    {
        cout << "Lets play!";
    }

    return 0;
}

Keep your spirit high, and keep going! Learning is a fun process!

Edited by Kjell Andersson

Share this post


Link to post
Share on other sites

you should also post these questions in general/beginners or even game programming forums, this particular board isn't exactly for helping with problems.

Edited by slicer4ever

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!