A few days ago I asked this question. So far I have made many changes in the code, as well as added some on and I was wondering if you see any way the code could be obviously optimized, as well as any suggestions you may have. Note: I was thinking for the vampire race I would create a const variable called vampireFoodBar or something, and when something happens, either use ++ or --. It seems kinda hackish and sloppy, so is there any better way to do this?#include <iostream>#include <string>#include <limits>#include <fstream> //Function that creates pointer > Icon...Im lazy. void createIcon(void) {     std::cout << >;}//Function clears cinvoid cinClear(void) {     using namespace std;    cin.clear();    cin.ignore(numeric_limits<streamsize>::max(), '\n');}//Defines player class and attributesclass Player {    public:         std::string name;         int age;         int gender;        int race;    };int main(void) {    Player user;    //Acquires players first name     std::string introOne = Welcome to The World of Magick\nWhat is your name?\n;    std::cout << introOne;    std::cin >> user.name;    //Asks for players gender     std::cout << \nHello  << user.name << .;    //While loop to surround gender choice code, so if the user fucks up they can try again     while(true) {         std::cout << \nAre you a boy or a girl?\n         1. Boy | 2. Girl\n         Choices are selected by typing in a single number\n;        //Asks for players gender         int playerGenderSelect;        createIcon();        std::cin >> playerGenderSelect;        //Sets gender depending on value entered. 1 being male, 2 being female.         switch(playerGenderSelect) {             case 1:                user.gender = 1;                break;            case 2:                user.gender = 2;                break;            default:                 std::cout << \nNot a valid number, try again\n;                user.gender = 3;            }    //If the player entered a valid number, break loop, if not, continue it.        if(user.gender == 1 or user.gender == 2) {            break;        }               else {            cinClear();            continue;        }     }    while(true) {         //Asks players for race.         int raceChoose;         std::cout << \nPlease choose a race:\n                    1. Elf\n                    2. Human\n                    3. Vampire\n                    4. Druid\n                    5. Troll\n                    6. Orc\n                    7. Dwarf\n                    8. Race Info\n;        std::cin >> raceChoose;                 //Shit ton of writing.         std::string raceHelpElf = Elf - The elves are an ancient race, older than all except the Dwarf.\n                                 They are built on wisdom, and intelligence.\n                                Many elves live in the wild, hunting their food with a sharp aim and a quick wit.\n                                Elves have mastered the art of the bow, and are stealthier than any race known to Algoria\n                                Elves are also jovial, light and happy by nature, throwing grand festivals day and night\n\n;        std::string raceHelpHuman = Human - The humans are the newest race to Algoria.\n                                    They are known by other races to be greedy and power-hungry.\n                                    Humans are the most ednuring creatures, and can survivie much.\n                                    Humans are generally more equipped at fighting disease and poison.\n                                    Humans are built on a race to power and control.\n\n;         switch(raceChoose) {            case 1:                //Sets race to Elf                user.race = 1;                break;            case 2:                //Sets race to Human                user.race = 2;                break;            case 3:                //Sets race to Vampire                user.race = 3;                break;            case 4:                 //Sets race to Druid                user.race = 4;                break;            case 5:                 //Sets race to Troll                user.race = 5;                break;            case 6:                 //Sets race to Orc                user.race = 6;                break;            case 7:                //Sets race to Dwarf                user.race = 7;                break;                //Sets race so it will print help.             case 8:                user.race = 8;                 break;            default:                 std::cout << Not a vaild number, try again.;                user.race = 0;        }            if(user.race >= 1 and user.race <= 10 and user.race != 8) {                break;            }            else if(user.race == 8) {                //Prints out all race help info                 std::cout <<                 \n\n <<                 raceHelpElf <<                raceHelpHuman <<                raceHelpVampire;                 continue;             }            else {                 //Clears cin and reruns loop                using namespace std;                cinClear();                continue;            }    }} 
Update on text based adventure game in C++
c++;beginner;adventure game
Use scoped enumerationsModern C++ provides scoped enumerations:enum class Gender {    femail,    male};enum class Race {    elf,    human,    orc};Why not use them instead of integer constants 1, 2, 3, ...?Data encapsulationAlso, I would suggest you keep the name, race, etc. fields as private, provide a constructor for Player, and the getters for getting all the four fields. This is not quite important in your code snippet, yet sometimes we need to maintain a particular class invariant via class methods, that check that the invariant is maintained. In such situation exporting the implementation might allow messing with those class invariants. (For example, a date class may not have a date with value 32.)For instance:class Player {private:    std::string name;    int age;    Gender gender;    Race race;public:    Player(std::string& name_arg,           int age_arg,           Gender gender_arg,           Race race_arg) :    name    {name_arg},    age     {age_arg},    gender  {gender_arg},    race    {race_arg}    {}    std::string& get_name() { return name; }    int get_age()           { return age; }    Gender get_gender()     { return gender; }    Race get_race()         { return race; }};Hope that helps.