Adventure Game (text based) in C++ The Next CEO of Stack OverflowProducer/Consumer...

Return the Closest Prime Number

How can I quit an app using Terminal?

Robert Sheckley short story about vacation spots being overwhelmed

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How do spells that require an ability check vs. the caster's spell save DC work?

Too much space between section and text in a twocolumn document

What is the purpose of the Evocation wizard's Potent Cantrip feature?

What does this shorthand mean?

How easy is it to start Magic from scratch?

% symbol leads to superlong (forever?) compilations

Does it take more energy to get to Venus or to Mars?

Term for the "extreme-extension" version of a straw man fallacy?

Why do remote companies require working in the US?

Is HostGator storing my password in plaintext?

MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs

How to write papers efficiently when English isn't my first language?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

How did people program for Consoles with multiple CPUs?

Is a stroke of luck acceptable after a series of unfavorable events?

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

Rotate a column

Can I equip Skullclamp on a creature I am sacrificing?

How to make a software documentation "officially" citable?

Describing a person. What needs to be mentioned?



Adventure Game (text based) in C++



The Next CEO of Stack OverflowProducer/Consumer implementation using condition_variableSimple multithreading C projectText-based adventure gameThe Mysts of Altair - text-based adventure gameText-based adventure survival horror gameFirst text-based adventure gameText based adventure game navigationText-based Adventure-Game EngineJava text-based adventure gameA little C++ based 2D game engine I madeShort text-based adventure gameText-based adventure and combat game












13












$begingroup$


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 <iostream>
#include <string>
#include <ctime>

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 << "Please input character name: ";
cin >> 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 << createChar.name << endl;
cout << createChar.health << endl;
cout << createChar.mana << endl;
cout << createChar.strength << endl;
cout << createChar.stamina << endl;
cout << createChar.intellect << endl;
cout << createChar.weaponAttack << endl;
cout << createChar.spellAttack << endl;
cout << createChar.souls << endl;
}









share|improve this question











$endgroup$












  • $begingroup$
    Take a look at "ncurses" library.
    $endgroup$
    – outoftime
    Mar 16 at 22:48






  • 2




    $begingroup$
    If your goal is to write a text adventure (and not just a C++ exercise), have a look at the existing text adventure engines such as TADS and Inform 7. If you still decide to go with C++, understanding the architecture and feature sets in the existing engines will advise you in your own code's larger design.
    $endgroup$
    – user117529
    Mar 17 at 2:46


















13












$begingroup$


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 <iostream>
#include <string>
#include <ctime>

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 << "Please input character name: ";
cin >> 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 << createChar.name << endl;
cout << createChar.health << endl;
cout << createChar.mana << endl;
cout << createChar.strength << endl;
cout << createChar.stamina << endl;
cout << createChar.intellect << endl;
cout << createChar.weaponAttack << endl;
cout << createChar.spellAttack << endl;
cout << createChar.souls << endl;
}









share|improve this question











$endgroup$












  • $begingroup$
    Take a look at "ncurses" library.
    $endgroup$
    – outoftime
    Mar 16 at 22:48






  • 2




    $begingroup$
    If your goal is to write a text adventure (and not just a C++ exercise), have a look at the existing text adventure engines such as TADS and Inform 7. If you still decide to go with C++, understanding the architecture and feature sets in the existing engines will advise you in your own code's larger design.
    $endgroup$
    – user117529
    Mar 17 at 2:46
















13












13








13


3



$begingroup$


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 <iostream>
#include <string>
#include <ctime>

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 << "Please input character name: ";
cin >> 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 << createChar.name << endl;
cout << createChar.health << endl;
cout << createChar.mana << endl;
cout << createChar.strength << endl;
cout << createChar.stamina << endl;
cout << createChar.intellect << endl;
cout << createChar.weaponAttack << endl;
cout << createChar.spellAttack << endl;
cout << createChar.souls << endl;
}









share|improve this question











$endgroup$




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 <iostream>
#include <string>
#include <ctime>

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 << "Please input character name: ";
cin >> 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 << createChar.name << endl;
cout << createChar.health << endl;
cout << createChar.mana << endl;
cout << createChar.strength << endl;
cout << createChar.stamina << endl;
cout << createChar.intellect << endl;
cout << createChar.weaponAttack << endl;
cout << createChar.spellAttack << endl;
cout << createChar.souls << endl;
}






c++ beginner game adventure-game






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 16 at 4:41







Justin

















asked Mar 16 at 1:43









JustinJustin

663




663












  • $begingroup$
    Take a look at "ncurses" library.
    $endgroup$
    – outoftime
    Mar 16 at 22:48






  • 2




    $begingroup$
    If your goal is to write a text adventure (and not just a C++ exercise), have a look at the existing text adventure engines such as TADS and Inform 7. If you still decide to go with C++, understanding the architecture and feature sets in the existing engines will advise you in your own code's larger design.
    $endgroup$
    – user117529
    Mar 17 at 2:46




















  • $begingroup$
    Take a look at "ncurses" library.
    $endgroup$
    – outoftime
    Mar 16 at 22:48






  • 2




    $begingroup$
    If your goal is to write a text adventure (and not just a C++ exercise), have a look at the existing text adventure engines such as TADS and Inform 7. If you still decide to go with C++, understanding the architecture and feature sets in the existing engines will advise you in your own code's larger design.
    $endgroup$
    – user117529
    Mar 17 at 2:46


















$begingroup$
Take a look at "ncurses" library.
$endgroup$
– outoftime
Mar 16 at 22:48




$begingroup$
Take a look at "ncurses" library.
$endgroup$
– outoftime
Mar 16 at 22:48




2




2




$begingroup$
If your goal is to write a text adventure (and not just a C++ exercise), have a look at the existing text adventure engines such as TADS and Inform 7. If you still decide to go with C++, understanding the architecture and feature sets in the existing engines will advise you in your own code's larger design.
$endgroup$
– user117529
Mar 17 at 2:46






$begingroup$
If your goal is to write a text adventure (and not just a C++ exercise), have a look at the existing text adventure engines such as TADS and Inform 7. If you still decide to go with C++, understanding the architecture and feature sets in the existing engines will advise you in your own code's larger design.
$endgroup$
– user117529
Mar 17 at 2:46












3 Answers
3






active

oldest

votes


















10












$begingroup$

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& name) {
this->name = name;
this->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->strength = randint(5, 10);


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






share|improve this answer











$endgroup$













  • $begingroup$
    I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
    $endgroup$
    – Justin
    Mar 16 at 4:07












  • $begingroup$
    Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
    $endgroup$
    – Justin
    Mar 16 at 4:26












  • $begingroup$
    randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
    $endgroup$
    – AJNeufeld
    Mar 16 at 5:13






  • 3




    $begingroup$
    @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
    $endgroup$
    – Quuxplusone
    Mar 16 at 5:33










  • $begingroup$
    Nice answer, though rand() shouldn't be used, <random> is recommend instead
    $endgroup$
    – JVApen
    Mar 18 at 19:06



















5












$begingroup$


  • Don't use using namespace std

  • Your comments add nothing to the program so leave them out. In general comments should tell you why not what. You should try to write self-explaining code. I.e. choose good names for your variables and functions so comments become almost unnecessary.


  • system("pause"); is not portable and can only be used on Windows.

  • Unless you depend on the return code you can omit return 0 from main. See http://c0x.coding-guidelines.com/5.1.2.2.3.html.

  • It is better to use random than relying on srand/rand. You're also missing the header for it (<cstdlib>) and the qualifier (std::). See also https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful.

  • Prefer using n over std::endl


In general you should read more about the Language and Programming. Here are some links to get you started:




  • C++ book list

  • C++ Super-FAQ

  • C++ Core Guidelines

  • cppreference






share|improve this answer









$endgroup$





















    3












    $begingroup$

    First, try not to declare all your types in the global namespace. Make your "own" space. This limits the exposure to other code you might integrate with.



    Your materials, weapons, and spells seem to be enum candidates as they are used as values. So use them as enum-values and define there size explicitly. In this case I'm not recommending scoped enums since you want to do calculations easily on there values.



    Added a constructor to your character.



    characterCreation function should take string by universal reference to avoid unnecessary copies.



    Have you print method take and ostream so you easily can change to the any stream of your choosing.



    namespace YourNamespaceName {

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

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

    enum spells : int {
    fire = 4, frost = 6, dark = 8, chaos = 10
    };

    struct character {
    explicit character(std::string &&name)
    : name(std::move(name)), strength(rand() % 5 + 5), stamina(rand() % 5 + 5), intellect(rand() % 5 + 5),
    weaponAttack(weapons::dagger * materials::bronze + 2 * strength),
    spellAttack(spells::fire + intellect * 2) {
    health += 2 * stamina;
    mana += 3 * intellect;
    }

    std::string name;
    int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
    };

    // Function Declaration
    character characterCreation(std::string &&name);

    std::ostream &printInfo(std::ostream &os, const character &createChar);

    } // close YourNamespaceName namespace

    // Main Function

    int main() {
    std::string characterName;
    std::cout << "Please input character name: ";
    std::cin >> characterName;

    std::srand(std::time(nullptr));
    auto player = YourNamespaceName::characterCreation(std::move(characterName));
    YourNamespaceName::printInfo(std::cout, player);

    system("pause");
    return 0;
    }

    namespace YourNamespaceName {

    // Function Definition

    character characterCreation(std::string &&name) {
    return character(std::move(name));
    }

    std::ostream &printInfo(std::ostream &os, const character &createChar) {
    return os << createChar.name << 'n'
    << createChar.health << 'n'
    << createChar.mana << 'n'
    << createChar.strength << 'n'
    << createChar.stamina << 'n'
    << createChar.intellect << 'n'
    << createChar.weaponAttack << 'n'
    << createChar.spellAttack << 'n'
    << createChar.souls << 'n';
    }

    } // close YourNamespaceName namespace





    share|improve this answer









    $endgroup$














      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "196"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215542%2fadventure-game-text-based-in-c%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      10












      $begingroup$

      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& name) {
      this->name = name;
      this->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->strength = randint(5, 10);


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






      share|improve this answer











      $endgroup$













      • $begingroup$
        I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
        $endgroup$
        – Justin
        Mar 16 at 4:07












      • $begingroup$
        Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
        $endgroup$
        – Justin
        Mar 16 at 4:26












      • $begingroup$
        randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
        $endgroup$
        – AJNeufeld
        Mar 16 at 5:13






      • 3




        $begingroup$
        @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
        $endgroup$
        – Quuxplusone
        Mar 16 at 5:33










      • $begingroup$
        Nice answer, though rand() shouldn't be used, <random> is recommend instead
        $endgroup$
        – JVApen
        Mar 18 at 19:06
















      10












      $begingroup$

      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& name) {
      this->name = name;
      this->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->strength = randint(5, 10);


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






      share|improve this answer











      $endgroup$













      • $begingroup$
        I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
        $endgroup$
        – Justin
        Mar 16 at 4:07












      • $begingroup$
        Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
        $endgroup$
        – Justin
        Mar 16 at 4:26












      • $begingroup$
        randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
        $endgroup$
        – AJNeufeld
        Mar 16 at 5:13






      • 3




        $begingroup$
        @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
        $endgroup$
        – Quuxplusone
        Mar 16 at 5:33










      • $begingroup$
        Nice answer, though rand() shouldn't be used, <random> is recommend instead
        $endgroup$
        – JVApen
        Mar 18 at 19:06














      10












      10








      10





      $begingroup$

      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& name) {
      this->name = name;
      this->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->strength = randint(5, 10);


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






      share|improve this answer











      $endgroup$



      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& name) {
      this->name = name;
      this->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->strength = randint(5, 10);


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







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 16 at 14:22









      Vogel612

      21.9k447131




      21.9k447131










      answered Mar 16 at 2:22









      QuuxplusoneQuuxplusone

      12.8k12062




      12.8k12062












      • $begingroup$
        I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
        $endgroup$
        – Justin
        Mar 16 at 4:07












      • $begingroup$
        Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
        $endgroup$
        – Justin
        Mar 16 at 4:26












      • $begingroup$
        randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
        $endgroup$
        – AJNeufeld
        Mar 16 at 5:13






      • 3




        $begingroup$
        @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
        $endgroup$
        – Quuxplusone
        Mar 16 at 5:33










      • $begingroup$
        Nice answer, though rand() shouldn't be used, <random> is recommend instead
        $endgroup$
        – JVApen
        Mar 18 at 19:06


















      • $begingroup$
        I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
        $endgroup$
        – Justin
        Mar 16 at 4:07












      • $begingroup$
        Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
        $endgroup$
        – Justin
        Mar 16 at 4:26












      • $begingroup$
        randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
        $endgroup$
        – AJNeufeld
        Mar 16 at 5:13






      • 3




        $begingroup$
        @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
        $endgroup$
        – Quuxplusone
        Mar 16 at 5:33










      • $begingroup$
        Nice answer, though rand() shouldn't be used, <random> is recommend instead
        $endgroup$
        – JVApen
        Mar 18 at 19:06
















      $begingroup$
      I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
      $endgroup$
      – Justin
      Mar 16 at 4:07






      $begingroup$
      I apologize, I should have clarified what my code is doing and what my expectations were. My post is not a troll, I prefer not to waste peoples time if I do not have to. I will make edits to the question. The numbers on the materials, weapons, and spells simply represent the amount of damage.
      $endgroup$
      – Justin
      Mar 16 at 4:07














      $begingroup$
      Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
      $endgroup$
      – Justin
      Mar 16 at 4:26






      $begingroup$
      Thank you for the insight and helpful post though. I will take a look at more constructors and destructors. I used the struct with the hopes that I would be able to create a large combination of different weapon types/spells, being that my class has only just begun using structs I am not too familiar with constructors/destructors.
      $endgroup$
      – Justin
      Mar 16 at 4:26














      $begingroup$
      randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
      $endgroup$
      – AJNeufeld
      Mar 16 at 5:13




      $begingroup$
      randint(5,10), as written, only generates 5 to 9, inclusive. You’d want hi - lo + 1 to get the full range.
      $endgroup$
      – AJNeufeld
      Mar 16 at 5:13




      3




      3




      $begingroup$
      @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
      $endgroup$
      – Quuxplusone
      Mar 16 at 5:33




      $begingroup$
      @AJNeufeld: Half-open ranges are the building blocks of C++ (as well as most other programming languages), and the sooner OP gets familiar with them, the better. See here and here for places I've used the phrase "half-open range" in previous reviews.
      $endgroup$
      – Quuxplusone
      Mar 16 at 5:33












      $begingroup$
      Nice answer, though rand() shouldn't be used, <random> is recommend instead
      $endgroup$
      – JVApen
      Mar 18 at 19:06




      $begingroup$
      Nice answer, though rand() shouldn't be used, <random> is recommend instead
      $endgroup$
      – JVApen
      Mar 18 at 19:06













      5












      $begingroup$


      • Don't use using namespace std

      • Your comments add nothing to the program so leave them out. In general comments should tell you why not what. You should try to write self-explaining code. I.e. choose good names for your variables and functions so comments become almost unnecessary.


      • system("pause"); is not portable and can only be used on Windows.

      • Unless you depend on the return code you can omit return 0 from main. See http://c0x.coding-guidelines.com/5.1.2.2.3.html.

      • It is better to use random than relying on srand/rand. You're also missing the header for it (<cstdlib>) and the qualifier (std::). See also https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful.

      • Prefer using n over std::endl


      In general you should read more about the Language and Programming. Here are some links to get you started:




      • C++ book list

      • C++ Super-FAQ

      • C++ Core Guidelines

      • cppreference






      share|improve this answer









      $endgroup$


















        5












        $begingroup$


        • Don't use using namespace std

        • Your comments add nothing to the program so leave them out. In general comments should tell you why not what. You should try to write self-explaining code. I.e. choose good names for your variables and functions so comments become almost unnecessary.


        • system("pause"); is not portable and can only be used on Windows.

        • Unless you depend on the return code you can omit return 0 from main. See http://c0x.coding-guidelines.com/5.1.2.2.3.html.

        • It is better to use random than relying on srand/rand. You're also missing the header for it (<cstdlib>) and the qualifier (std::). See also https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful.

        • Prefer using n over std::endl


        In general you should read more about the Language and Programming. Here are some links to get you started:




        • C++ book list

        • C++ Super-FAQ

        • C++ Core Guidelines

        • cppreference






        share|improve this answer









        $endgroup$
















          5












          5








          5





          $begingroup$


          • Don't use using namespace std

          • Your comments add nothing to the program so leave them out. In general comments should tell you why not what. You should try to write self-explaining code. I.e. choose good names for your variables and functions so comments become almost unnecessary.


          • system("pause"); is not portable and can only be used on Windows.

          • Unless you depend on the return code you can omit return 0 from main. See http://c0x.coding-guidelines.com/5.1.2.2.3.html.

          • It is better to use random than relying on srand/rand. You're also missing the header for it (<cstdlib>) and the qualifier (std::). See also https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful.

          • Prefer using n over std::endl


          In general you should read more about the Language and Programming. Here are some links to get you started:




          • C++ book list

          • C++ Super-FAQ

          • C++ Core Guidelines

          • cppreference






          share|improve this answer









          $endgroup$




          • Don't use using namespace std

          • Your comments add nothing to the program so leave them out. In general comments should tell you why not what. You should try to write self-explaining code. I.e. choose good names for your variables and functions so comments become almost unnecessary.


          • system("pause"); is not portable and can only be used on Windows.

          • Unless you depend on the return code you can omit return 0 from main. See http://c0x.coding-guidelines.com/5.1.2.2.3.html.

          • It is better to use random than relying on srand/rand. You're also missing the header for it (<cstdlib>) and the qualifier (std::). See also https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful.

          • Prefer using n over std::endl


          In general you should read more about the Language and Programming. Here are some links to get you started:




          • C++ book list

          • C++ Super-FAQ

          • C++ Core Guidelines

          • cppreference







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 16 at 11:37









          yuriyuri

          3,68721034




          3,68721034























              3












              $begingroup$

              First, try not to declare all your types in the global namespace. Make your "own" space. This limits the exposure to other code you might integrate with.



              Your materials, weapons, and spells seem to be enum candidates as they are used as values. So use them as enum-values and define there size explicitly. In this case I'm not recommending scoped enums since you want to do calculations easily on there values.



              Added a constructor to your character.



              characterCreation function should take string by universal reference to avoid unnecessary copies.



              Have you print method take and ostream so you easily can change to the any stream of your choosing.



              namespace YourNamespaceName {

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

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

              enum spells : int {
              fire = 4, frost = 6, dark = 8, chaos = 10
              };

              struct character {
              explicit character(std::string &&name)
              : name(std::move(name)), strength(rand() % 5 + 5), stamina(rand() % 5 + 5), intellect(rand() % 5 + 5),
              weaponAttack(weapons::dagger * materials::bronze + 2 * strength),
              spellAttack(spells::fire + intellect * 2) {
              health += 2 * stamina;
              mana += 3 * intellect;
              }

              std::string name;
              int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
              };

              // Function Declaration
              character characterCreation(std::string &&name);

              std::ostream &printInfo(std::ostream &os, const character &createChar);

              } // close YourNamespaceName namespace

              // Main Function

              int main() {
              std::string characterName;
              std::cout << "Please input character name: ";
              std::cin >> characterName;

              std::srand(std::time(nullptr));
              auto player = YourNamespaceName::characterCreation(std::move(characterName));
              YourNamespaceName::printInfo(std::cout, player);

              system("pause");
              return 0;
              }

              namespace YourNamespaceName {

              // Function Definition

              character characterCreation(std::string &&name) {
              return character(std::move(name));
              }

              std::ostream &printInfo(std::ostream &os, const character &createChar) {
              return os << createChar.name << 'n'
              << createChar.health << 'n'
              << createChar.mana << 'n'
              << createChar.strength << 'n'
              << createChar.stamina << 'n'
              << createChar.intellect << 'n'
              << createChar.weaponAttack << 'n'
              << createChar.spellAttack << 'n'
              << createChar.souls << 'n';
              }

              } // close YourNamespaceName namespace





              share|improve this answer









              $endgroup$


















                3












                $begingroup$

                First, try not to declare all your types in the global namespace. Make your "own" space. This limits the exposure to other code you might integrate with.



                Your materials, weapons, and spells seem to be enum candidates as they are used as values. So use them as enum-values and define there size explicitly. In this case I'm not recommending scoped enums since you want to do calculations easily on there values.



                Added a constructor to your character.



                characterCreation function should take string by universal reference to avoid unnecessary copies.



                Have you print method take and ostream so you easily can change to the any stream of your choosing.



                namespace YourNamespaceName {

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

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

                enum spells : int {
                fire = 4, frost = 6, dark = 8, chaos = 10
                };

                struct character {
                explicit character(std::string &&name)
                : name(std::move(name)), strength(rand() % 5 + 5), stamina(rand() % 5 + 5), intellect(rand() % 5 + 5),
                weaponAttack(weapons::dagger * materials::bronze + 2 * strength),
                spellAttack(spells::fire + intellect * 2) {
                health += 2 * stamina;
                mana += 3 * intellect;
                }

                std::string name;
                int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
                };

                // Function Declaration
                character characterCreation(std::string &&name);

                std::ostream &printInfo(std::ostream &os, const character &createChar);

                } // close YourNamespaceName namespace

                // Main Function

                int main() {
                std::string characterName;
                std::cout << "Please input character name: ";
                std::cin >> characterName;

                std::srand(std::time(nullptr));
                auto player = YourNamespaceName::characterCreation(std::move(characterName));
                YourNamespaceName::printInfo(std::cout, player);

                system("pause");
                return 0;
                }

                namespace YourNamespaceName {

                // Function Definition

                character characterCreation(std::string &&name) {
                return character(std::move(name));
                }

                std::ostream &printInfo(std::ostream &os, const character &createChar) {
                return os << createChar.name << 'n'
                << createChar.health << 'n'
                << createChar.mana << 'n'
                << createChar.strength << 'n'
                << createChar.stamina << 'n'
                << createChar.intellect << 'n'
                << createChar.weaponAttack << 'n'
                << createChar.spellAttack << 'n'
                << createChar.souls << 'n';
                }

                } // close YourNamespaceName namespace





                share|improve this answer









                $endgroup$
















                  3












                  3








                  3





                  $begingroup$

                  First, try not to declare all your types in the global namespace. Make your "own" space. This limits the exposure to other code you might integrate with.



                  Your materials, weapons, and spells seem to be enum candidates as they are used as values. So use them as enum-values and define there size explicitly. In this case I'm not recommending scoped enums since you want to do calculations easily on there values.



                  Added a constructor to your character.



                  characterCreation function should take string by universal reference to avoid unnecessary copies.



                  Have you print method take and ostream so you easily can change to the any stream of your choosing.



                  namespace YourNamespaceName {

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

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

                  enum spells : int {
                  fire = 4, frost = 6, dark = 8, chaos = 10
                  };

                  struct character {
                  explicit character(std::string &&name)
                  : name(std::move(name)), strength(rand() % 5 + 5), stamina(rand() % 5 + 5), intellect(rand() % 5 + 5),
                  weaponAttack(weapons::dagger * materials::bronze + 2 * strength),
                  spellAttack(spells::fire + intellect * 2) {
                  health += 2 * stamina;
                  mana += 3 * intellect;
                  }

                  std::string name;
                  int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
                  };

                  // Function Declaration
                  character characterCreation(std::string &&name);

                  std::ostream &printInfo(std::ostream &os, const character &createChar);

                  } // close YourNamespaceName namespace

                  // Main Function

                  int main() {
                  std::string characterName;
                  std::cout << "Please input character name: ";
                  std::cin >> characterName;

                  std::srand(std::time(nullptr));
                  auto player = YourNamespaceName::characterCreation(std::move(characterName));
                  YourNamespaceName::printInfo(std::cout, player);

                  system("pause");
                  return 0;
                  }

                  namespace YourNamespaceName {

                  // Function Definition

                  character characterCreation(std::string &&name) {
                  return character(std::move(name));
                  }

                  std::ostream &printInfo(std::ostream &os, const character &createChar) {
                  return os << createChar.name << 'n'
                  << createChar.health << 'n'
                  << createChar.mana << 'n'
                  << createChar.strength << 'n'
                  << createChar.stamina << 'n'
                  << createChar.intellect << 'n'
                  << createChar.weaponAttack << 'n'
                  << createChar.spellAttack << 'n'
                  << createChar.souls << 'n';
                  }

                  } // close YourNamespaceName namespace





                  share|improve this answer









                  $endgroup$



                  First, try not to declare all your types in the global namespace. Make your "own" space. This limits the exposure to other code you might integrate with.



                  Your materials, weapons, and spells seem to be enum candidates as they are used as values. So use them as enum-values and define there size explicitly. In this case I'm not recommending scoped enums since you want to do calculations easily on there values.



                  Added a constructor to your character.



                  characterCreation function should take string by universal reference to avoid unnecessary copies.



                  Have you print method take and ostream so you easily can change to the any stream of your choosing.



                  namespace YourNamespaceName {

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

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

                  enum spells : int {
                  fire = 4, frost = 6, dark = 8, chaos = 10
                  };

                  struct character {
                  explicit character(std::string &&name)
                  : name(std::move(name)), strength(rand() % 5 + 5), stamina(rand() % 5 + 5), intellect(rand() % 5 + 5),
                  weaponAttack(weapons::dagger * materials::bronze + 2 * strength),
                  spellAttack(spells::fire + intellect * 2) {
                  health += 2 * stamina;
                  mana += 3 * intellect;
                  }

                  std::string name;
                  int health = 100, mana = 100, strength, stamina, intellect, weaponAttack, spellAttack, souls = 0;
                  };

                  // Function Declaration
                  character characterCreation(std::string &&name);

                  std::ostream &printInfo(std::ostream &os, const character &createChar);

                  } // close YourNamespaceName namespace

                  // Main Function

                  int main() {
                  std::string characterName;
                  std::cout << "Please input character name: ";
                  std::cin >> characterName;

                  std::srand(std::time(nullptr));
                  auto player = YourNamespaceName::characterCreation(std::move(characterName));
                  YourNamespaceName::printInfo(std::cout, player);

                  system("pause");
                  return 0;
                  }

                  namespace YourNamespaceName {

                  // Function Definition

                  character characterCreation(std::string &&name) {
                  return character(std::move(name));
                  }

                  std::ostream &printInfo(std::ostream &os, const character &createChar) {
                  return os << createChar.name << 'n'
                  << createChar.health << 'n'
                  << createChar.mana << 'n'
                  << createChar.strength << 'n'
                  << createChar.stamina << 'n'
                  << createChar.intellect << 'n'
                  << createChar.weaponAttack << 'n'
                  << createChar.spellAttack << 'n'
                  << createChar.souls << 'n';
                  }

                  } // close YourNamespaceName namespace






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 16 at 14:12









                  Bo RBo R

                  19112




                  19112






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Code Review Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215542%2fadventure-game-text-based-in-c%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Nidaros erkebispedøme

                      Birsay

                      Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?