Advertisement

So I made this... Help xD

Started by September 06, 2013 08:04 PM
2 comments, last by JTippetts 11 years, 5 months ago
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;
}

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!

Advertisement

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

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Moving to For Beginners

This topic is closed to new replies.

Advertisement