Adventure Game (text based) in C++ I'm working on a simple text based adventure game. I've just finished working on the character creation portion. The code works perfectly fine when run, but I would just like to get some feedback to ensure that it checks off from a professional and efficient standpoint.

The values of the materials, weapons, and spells are representing the amount of damage points each does for further and future calculations with the characters stats later in the game.

The code itself essentially allows you to input a characters name. Then, the strength, stamina, and intellect is randomly generated so that your character build is different at the beginning of each game. Then, once that has finished, the code takes into account the weapon type, the material of the weapon, the spell type and adds additional damage based on the players stats.

I would just like to know if there is a better way of writing my code to make it look cleaner, or if there possibly any concerns that might cause me issues down the road when I add more functionality to the game. Seeing as I am a beginner to C++, I am not incredibly great at determining whether my code is optimal or not.

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;ctime&gt;

using namespace std;

/* Materials Structure */

typedef struct materials {
    int wood = 1, oak = 2, maple = 3, ash = 4, bronze = 2, iron = 3, steel = 4, mithril = 5, dragon = 6;
};

/* Weapon Structure */

typedef struct weapons {
    int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
} weapons;

/* Spell Structure */

typedef struct spells {
    int fire = 4, frost = 6, dark = 8, chaos = 10;
} spells;


/* Character Structure */

typedef struct character {
    string name;
    int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
    spells spell;
    weapons weapon;
    materials material;
} character;

/* Function Declaration */

character characterCreation(string name);
void printInfo(character createChar);

/* Main Function */

int main() {
    string characterName;
    cout &lt;&lt; "Please input character name: ";
    cin &gt;&gt; characterName;

    srand(time(NULL));
    character player = characterCreation(characterName);
    printInfo(player);

    system("pause");
    return 0;
}

/* Function Definition */

character characterCreation(string name) {
    character createChar;
    createChar.name = name;
    createChar.strength = rand() % 5 + 5;
    createChar.stamina = rand() % 5 + 5;
    createChar.intellect = rand() % 5 + 5;
    createChar.health += 2 * createChar.stamina;
    createChar.mana += 3 * createChar.intellect;
    createChar.weaponAttack = (createChar.weapon.dagger * createChar.material.bronze) + (2 * createChar.strength);
    createChar.spellAttack = (createChar.spell.fire + (createChar.intellect * 2));
    return createChar;
}

void printInfo(character createChar) {
    cout &lt;&lt; createChar.name &lt;&lt; endl;
    cout &lt;&lt; createChar.health &lt;&lt; endl;
    cout &lt;&lt; createChar.mana &lt;&lt; endl;
    cout &lt;&lt; createChar.strength &lt;&lt; endl;
    cout &lt;&lt; createChar.stamina &lt;&lt; endl;
    cout &lt;&lt; createChar.intellect &lt;&lt; endl;
    cout &lt;&lt; createChar.weaponAttack &lt;&lt; endl;
    cout &lt;&lt; createChar.spellAttack &lt;&lt; endl;
    cout &lt;&lt; createChar.souls &lt;&lt; endl;
}
typedef struct weapons {
    int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2;
} weapons;


The typedef struct X { ... } X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X { ... };.

You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was

enum class Weapon {
    dagger = 2,
    sword = 3,
    axe = 4,
    mace = 5,
};


so that you could later write

Weapon w = Weapon::sword;
if (w == Weapon::axe) { ... }


What you actually wrote, unfortunately, is simply nonsense.



character characterCreation(string name);


Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like

Character::Character(const std::string&amp; name) {
    this-&gt;name = name;
    this-&gt;strength = rand() % 5 + 5;
}


and so on.

Also consider writing yourself a helper function

int randint(int lo, int hi) {
    return rand() % (hi - lo) + lo;
}


so that you can write simply

    this-&gt;strength = randint(5, 10);


Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.