I'm making a simple text RPG game that I will later (once i get the code running well in the text version) put it to graphics and so on.

Basically what this code is doing is, there's a monster that the user just killed.
based on that monsters level that's how much experience it gives you.
this seems to work fine for me but i was wondering how i can make it so that at the main menu i can have something that says:

you are ____ experience away from leveling up.
but since I'm just using the: int lvl;
im not sure how i can do this.
also another problem i have is that every time that i kill a monster the random experience it gives me increases to over the amount that i want it to.

for example the first time i kill the goblin (level 1) it gives me say... 5 exp.
the second time it gives me say... 8 exp.
but then the third + time it gives me over 20 exp per. how do i avoid this?

if (goblin <= 0){
                          expe = expe + rand() % 10 + 1;
                          expe = expe * glvl;
                          texp = texp + expe;
                          cin.ignore();
                          loot = rand() % 100 + 1;
                          loot = loot * glvl;
                          cout << "You have killed a Goblin!\n";
                          cout << "\nYour loot is: ";
                          cout << loot << " Gold\n\n";
                          cout << "You also got: " << expe << " experience.\n\n";
                          cout << "Your total experience is: " << texp << "\n\n";
                          cout << "\nPress Enter to continue.\n\n";
                          money = money + loot;
                          cin.get();
                            if    (texp >= 50){
                                      system ("cls");
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                             else if (texp >=100){
                                      system ("cls");
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              else if (texp >=150){
                                      system ("cls");
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              else if (texp >=200){
                                      system ("cls");
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              else if (texp >=300){
                                      system ("cls");
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                               else if (texp >=400){
                                      system ("cls");
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                                 
                                 }

I have attached a file of the game so that you wouldn't have to compile it, the leveling is only functional on the "Goblin" monster so if you want to test it out you would have to fight that one.

Your expe keeps building because you keep adding itself with the new random exp to itself. If you want to just add the amount of exp for killing that goblin then you need to just assign the random exp gained to expe (like you did for loot). In other words change expe = expe + rand() % 10 + 1; to expe = rand() % 10 + 1; As for the show exp until next level part it looks like you would need to take the next level exp required and subtract the texp you have from it. Or you can restructure the exp system and have variables called currentExp, expToLevel and currentLevel.

So random some exp after you kill the NPC and add that to currentExp and check if it becomes greater than ExpToLevel. If it is then go currentExp = currentExp % expToLevel (this will carry the extra exp from "over leveling" to the next level) and add 1 to level. Then just make expToLevel = currentLevel * 50 meaning that if you are level 1 then you need 50 exp, level 2 100 exp and so on.

so now I did what you said, I also added a lot to the original code.
now i have a problem that when I level up, the program crashes, I tweaked the code and I'm not sure if I fixed it or not but anyway here's my code:

if you notice down at the bottom of the code I repeat a lot of my. Void functions and just tweak them a tiny bit.
is there anyway i can do this without adding so many lines to my code?

/*Coded by Josh*/

# include <iostream>
# include <cmath>
# include <ctime>
# include <conio.h>



using namespace std;


    int currentlvl;
    int exptolvl;
    int currentexp;
    int healing;
    int maxhealth;
    int points = 3;
    int loot = 0;
    int money;
    int dmg;
    int mdmg;
    int yourclass;
    string name; // lets the players name be up to 40 characters
    int choice;
    int goblin = 25; // monsters health.
    int dwarf = 50;
    int troll = 75;
    int giant = 100;
    int glvl = 1; // monsters level
    int dlvl = 2;
    int tlvl = 3;
    int Glvl = 4;
    int typeofclass;
    int health;
    int mana;
    int str;
    int def;
    int texp;
    int expe;
    int lvl = 1; // will require set ammount of exp.

void exit ();
void attpoints();
void mainmenu();
void shop ();
void rest ();
void arena ();
void heal();
void gmelee();
void gspell();
void gmagic();
void gclasshealing();
void gsuperstrike();
void glightningbolt();
void glightningstrike();
void gfrostbolt();
void gfirebolt();
void gfireball();
void dmelee();
void dspell();
void dmagic();
void dclasshealing();
void dsuperstrike();
void dlightningbolt();
void dlightningstrike();
void dfrostbolt();
void dfirebolt();
void dfireball();
void tmelee();
void tspell();
void tmagic();
void tclasshealing();
void tsuperstrike();
void tlightningbolt();
void tlightningstrike();
void tfrostbolt();
void tfirebolt();
void tfireball();
void Gmelee();
void Gspell();
void Gmagic();
void Gclasshealing();
void Gsuperstrike();
void Glightningbolt();
void Glightningstrike();
void Gfrostbolt();
void Gfirebolt();
void Gfireball();


 void fightg (){
      
             srand(static_cast<unsigned>(time(0)));
             bool done = false;
             goblin = 25;

              // do loop here, until the monsters health is <= 0
              system ("cls");
                  
                    
                    
                         do {
                             
                         dmg = 0;
                         mdmg = 0;
                         
                         if (health <= 0){
                         cout << "You have died." << endl << endl; // if you died from the fight then it will return to the main menu
                         cout << "Press Enter to return to the Main Menu.\n\n";
                         cin.ignore();
                         cin.get();
                         mainmenu();
                    }
                               
                         system ("cls");
                         cout << "Your health is: " << health << endl << endl;
                         cout << "The Goblin's heath is: " << goblin << endl << endl << endl;
                         cout << "Do you want to: " << endl << endl;
                         cout << "1. Attack." << endl << endl;
                         cout << "2. Heal." << endl << endl;
                         cout << "3. Go to Main menu." << endl << endl;
                         cin >> choice;
                           if (choice == 1){
                              do {
                              
                              system ("cls");
                              
                              cout << "What type of attack do you want to use?\n\n";
                              cout << "1. Melee.\n\n";
                              cout << "2. A Spell.\n\n";
                              cin >> choice;
                              switch (choice){
                                     case 1:
                                          done = true;
                                          gmelee();
                                     break;
                                     case 2:
                                          done = true;
                                          gspell();
                                     break;
                                     default:
                                          cout << "That is not a choice.\n\n";
                                          cout << "Press Enter to continue.\n\n";
                                          cin.ignore();
                                          cin.get();
                                     }
                                     } while (done != true);
                                     }
                               
                           else if (choice == 2){
                                   system ("cls") ;
                                   cout << "You have chosen to heal." << endl << endl;
                                   healing = rand() % 10 + 1;
                                   healing = healing * mana;
                                   healing = healing / 5;
                                   
                                   cout << "You healed: " << healing << ".\n";                                   
                                   mdmg = rand() % 10 + 1;
                                   mdmg = mdmg * glvl;
                                   mdmg = mdmg / def;
                                   health = health - mdmg;
                                   cout <<  "Your enemy hit you for:" << mdmg << endl << endl;
                                   cout << "Your health is now: " << health << endl << endl;
                                   cout << endl << endl;
                              cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
                              
                       
                                   // press any key code to go back to the main fighting menu.
                                }
                           else if (choice == 3){mainmenu ();}
                           else {
                                cout << "That is not a choice. please try again." << endl;
                                cout << "To continue fighing press Enter." << endl;
                                cin.ignore();
                                cin.get();
                                }
                            } while (goblin > 0);
                                 
                          
                          system("cls");
                          
               if (goblin <= 0){
                          expe = 0;
                          expe = rand() % 10 + 1;
                          expe = expe * glvl;
                          currentexp = currentexp + expe;
                          loot = rand() % 100 + 1;
                          loot = loot * glvl;
                          cout << "You have killed a Goblin!\n";
                          cout << "\nYour loot is: ";
                          cout << loot << " Gold\n\n";
                          cout << "You also got: " << expe << " experience.\n\n";
                          cout << "Your total experience is: " << currentexp << ".\n\n";
                          cout << "\nPress Enter to continue.\n\n";
                          money = money + loot;
                          cin.ignore();
                          cin.get();
                            if    (currentexp >= lvl * 50){
                                      system ("cls");
                                      currentexp = currentexp - (lvl * 50);
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cout << "You have Gained 3 Attribute points and 50 gold!\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              }
                          
                          
                          
                          mainmenu();
                          
                          }
                          


void fightd () {
     
            dwarf = 50;
     
             bool done = false;

              system ("cls");
                  
                    
                    
                         do {
                             
                         dmg = 0;
                         mdmg = 0;
                         
                         if (health <= 0){
                         cout << "You have died." << endl << endl; // if you died from the fight then it will return to the main menu
                         cout << "Press Enter to return to the Main Menu.\n\n";
                         cin.ignore();
                         cin.get();
                         mainmenu();
                    }
                               
                         system ("cls");
                         cout << "Your health is: " << health << endl << endl;
                         cout << "The Dwarf's heath is: " << dwarf << endl << endl << endl;
                         cout << "Do you want to: " << endl << endl;
                         cout << "1. Attack." << endl << endl;
                         cout << "2. Heal." << endl << endl;
                         cout << "3. Go to Main menu." << endl << endl;
                         cin >> choice;
                           if (choice == 1){
                              do {
                              
                              system ("cls");
                              
                              cout << "What type of attack do you want to use?\n\n";
                              cout << "1. Melee.\n\n";
                              cout << "2. A Spell.\n\n";
                              cin >> choice;
                              switch (choice){
                                     case 1:
                                          done = true;
                                          dmelee();
                                     break;
                                     case 2:
                                          done = true;
                                          dspell();
                                     break;
                                     default:
                                          cout << "That is not a choice.\n\n";
                                          cout << "Press Enter to continue.\n\n";
                                          cin.ignore();
                                          cin.get();
                                     }
                                     } while (done != true);
                                     }
                               
                           else if (choice == 2){
                                   system ("cls") ;
                                   cout << "You have chosen to heal." << endl << endl;
                                   healing = rand() % 10 + 1;
                                   healing = healing * mana;
                                   healing = healing / 5;
                                   
                                   cout << "You healed: " << healing << ".\n";                                   
                                   mdmg = rand() % 10 + 1;
                                   mdmg = mdmg * dlvl;
                                   mdmg = mdmg / def;
                                   health = health - mdmg;
                                   cout <<  "Your enemy hit you for:" << mdmg << endl << endl;
                                   cout << "Your health is now: " << health << endl << endl;
                                   cout << endl << endl;
                              cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
                              
                       
                                   // press any key code to go back to the main fighting menu.
                                }
                           else if (choice == 3){mainmenu ();}
                           else {
                                cout << "That is not a choice. please try again." << endl;
                                cout << "To continue fighing press Enter." << endl;
                                cin.ignore();
                                cin.get();
                                }
                            } while (dwarf > 0);
                                 
                          
                          system("cls");
                          
               if (dwarf <= 0){
                          expe = 0;
                          expe = rand() % 10 + 1;
                          expe = expe * dlvl;
                          currentexp = currentexp + expe;
                          loot = rand() % 100 + 1;
                          loot = loot * dlvl;
                          cout << "You have killed a Dwarf!\n";
                          cout << "\nYour loot is: ";
                          cout << loot << " Gold\n\n";
                          cout << "You also got: " << expe << " experience.\n\n";
                          cout << "Your total experience is: " << currentexp << ".\n\n";
                          cout << "\nPress Enter to continue.\n\n";
                          money = money + loot;
                          cin.ignore();
                          cin.get();
                            if    (currentexp >= lvl * 50){
                                      system ("cls");
                                      currentexp = currentexp - (lvl * 50);
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cout << "You have Gained 3 Attribute points and 50 gold!\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              }
                          
                          
                          
                          mainmenu();
                          
                          }
               
               
void fightt () {
     
            troll = 75;
            bool done = false;

              // do loop here, until the monsters health is <= 0
              system ("cls");
                  
                    
                    
                         do {
                             
                         dmg = 0;
                         mdmg = 0;
                         
                         if (health <= 0){
                         cout << "You have died." << endl << endl; // if you died from the fight then it will return to the main menu
                         cout << "Press Enter to return to the Main Menu.\n\n";
                         cin.ignore();
                         cin.get();
                         mainmenu();
                    }
                               
                         system ("cls");
                         cout << "Your health is: " << health << endl << endl;
                         cout << "The Troll's heath is: " << troll << endl << endl << endl;
                         cout << "Do you want to: " << endl << endl;
                         cout << "1. Attack." << endl << endl;
                         cout << "2. Heal." << endl << endl;
                         cout << "3. Go to Main menu." << endl << endl;
                         cin >> choice;
                           if (choice == 1){
                              do {
                              
                              system ("cls");
                              
                              cout << "What type of attack do you want to use?\n\n";
                              cout << "1. Melee.\n\n";
                              cout << "2. A Spell.\n\n";
                              cin >> choice;
                              switch (choice){
                                     case 1:
                                          done = true;
                                          tmelee();
                                     break;
                                     case 2:
                                          done = true;
                                          tspell();
                                     break;
                                     default:
                                          cout << "That is not a choice.\n\n";
                                          cout << "Press Enter to continue.\n\n";
                                          cin.ignore();
                                          cin.get();
                                     }
                                     } while (done != true);
                                     }
                               
                           else if (choice == 2){
                                   system ("cls") ;
                                   cout << "You have chosen to heal." << endl << endl;
                                   healing = rand() % 10 + 1;
                                   healing = healing * mana;
                                   healing = healing / 5;
                                   
                                   cout << "You healed: " << healing << ".\n";                                   
                                   mdmg = rand() % 10 + 1;
                                   mdmg = mdmg * tlvl;
                                   mdmg = mdmg / def;
                                   health = health - mdmg;
                                   cout <<  "Your enemy hit you for:" << mdmg << endl << endl;
                                   cout << "Your health is now: " << health << endl << endl;
                                   cout << endl << endl;
                              cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
                              
                       
                                   // press any key code to go back to the main fighting menu.
                                }
                           else if (choice == 3){mainmenu ();}
                           else {
                                cout << "That is not a choice. please try again." << endl;
                                cout << "To continue fighing press Enter." << endl;
                                cin.ignore();
                                cin.get();
                                }
                            } while (troll> 0);
                                 
                          
                          system("cls");
                          
               if (troll <= 0){
                          expe = 0;
                          expe = rand() % 10 + 1;
                          expe = expe * tlvl;
                          currentexp = currentexp + expe;
                          loot = rand() % 100 + 1;
                          loot = loot * tlvl;
                          cout << "You have killed a Troll!\n";
                          cout << "\nYour loot is: ";
                          cout << loot << " Gold\n\n";
                          cout << "You also got: " << expe << " experience.\n\n";
                          cout << "Your total experience is: " << currentexp << ".\n\n";
                          cout << "\nPress Enter to continue.\n\n";
                          money = money + loot;
                          cin.ignore();
                          cin.get();
                            if    (currentexp >= lvl * 50){
                                      system ("cls");
                                      currentexp = currentexp - (lvl * 50);
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cout << "You have Gained 3 Attribute points and 50 gold!\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              }
                          
                          
                          
                          mainmenu();
                          
                          }
               
               

void fightG () {
     
            giant = 100;
            
            bool done = false;

              // do loop here, until the monsters health is <= 0
              system ("cls");
                  
                    
                    
                         do {
                             
                         dmg = 0;
                         mdmg = 0;
                         
                         if (health <= 0){
                         cout << "You have died." << endl << endl; // if you died from the fight then it will return to the main menu
                         cout << "Press Enter to return to the Main Menu.\n\n";
                         cin.ignore();
                         cin.get();
                         mainmenu();
                    }
                               
                         system ("cls");
                         cout << "Your health is: " << health << endl << endl;
                         cout << "The Giant's heath is: " << giant << endl << endl << endl;
                         cout << "Do you want to: " << endl << endl;
                         cout << "1. Attack." << endl << endl;
                         cout << "2. Heal." << endl << endl;
                         cout << "3. Go to Main menu." << endl << endl;
                         cin >> choice;
                           if (choice == 1){
                              do {
                              
                              system ("cls");
                              
                              cout << "What type of attack do you want to use?\n\n";
                              cout << "1. Melee.\n\n";
                              cout << "2. A Spell.\n\n";
                              cin >> choice;
                              switch (choice){
                                     case 1:
                                          done = true;
                                          Gmelee();
                                     break;
                                     case 2:
                                          done = true;
                                          Gspell();
                                     break;
                                     default:
                                          cout << "That is not a choice.\n\n";
                                          cout << "Press Enter to continue.\n\n";
                                          cin.ignore();
                                          cin.get();
                                     }
                                     } while (done != true);
                                     }
                               
                           else if (choice == 2){
                                   system ("cls") ;
                                   cout << "You have chosen to heal." << endl << endl;
                                   healing = rand() % 10 + 1;
                                   healing = healing * mana;
                                   healing = healing / 5;
                                   
                                   cout << "You healed: " << healing << ".\n";                                   
                                   mdmg = rand() % 10 + 1;
                                   mdmg = mdmg * Glvl;
                                   mdmg = mdmg / def;
                                   health = health - mdmg;
                                   cout <<  "Your enemy hit you for:" << mdmg << endl << endl;
                                   cout << "Your health is now: " << health << endl << endl;
                                   cout << endl << endl;
                              cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
                              
                       
                                   // press any key code to go back to the main fighting menu.
                                }
                           else if (choice == 3){mainmenu ();}
                           else {
                                cout << "That is not a choice. please try again." << endl;
                                cout << "To continue fighing press Enter." << endl;
                                cin.ignore();
                                cin.get();
                                }
                            } while (giant > 0);
                                 
                          
                          system("cls");
                          
               if (giant <= 0){
                          expe = 0;
                          expe = rand() % 10 + 1;
                          expe = expe * Glvl;
                          currentexp = currentexp + expe;
                          loot = rand() % 100 + 1;
                          loot = loot * Glvl;
                          cout << "You have killed a Goblin!\n";
                          cout << "\nYour loot is: ";
                          cout << loot << " Gold\n\n";
                          cout << "You also got: " << expe << " experience.\n\n";
                          cout << "Your total experience is: " << currentexp << ".\n\n";
                          cout << "\nPress Enter to continue.\n\n";
                          money = money + loot;
                          cin.ignore();
                          cin.get();
                            if    (currentexp >= lvl * 50){
                                      system ("cls");
                                      currentexp = currentexp - (lvl * 50);
                                      lvl = lvl + 1;
                                      points = points + 3;
                                      cout << "Congratulations " << name << "\n\n";
                                      cout << "You have Leveled up!\n\n";
                                      cout << "You are now level: " << lvl << "\n\n";
                                      cout << "You have Gained 3 Attribute points and 50 gold!\n\n";
                                      cin.ignore();
                                      cout << "\nPress Enter to continue.\n\n";
                                      cin.get();
                                      }
                              }
                          
                          
                          
                          mainmenu();
                          
                          }


void mainmenu (){
     
    bool done = false;
    int choice;
    int goblin = 250; // monsters health.
    int dwarf = 500;
    int troll = 750;
    int giant = 1000;
    int glvl = 1; // monsters level
    int dlvl = 2;
    int tlvl = 3;
    int Glvl = 4;
    
    do {

    system ("cls");
    cout << "Main menu." << endl << endl; // Main menu
    cout << "Your health is: " << health << "\n\n";
    cout << "You have: " << money << " Gold.\n\n";
    cout << "You have: " << points << " Attribute points.\n\n";
    cout << "You have: " << currentexp << " Experience.\n\n";
    cout << "You need: " << (lvl * 50) - currentexp << " Experience to level up\n\n";
    cout << "What would you like to do " << name << "?" << endl << endl;
    cout << "1. Fight." << endl << endl;
    cout << "2. Go to the Shop." << endl << endl;
    cout << "3. Go to the Arena." << endl << endl;
    if (points > 0){
    cout << "4. Spend Attribute Points.\n\n";
}
    if (health != maxhealth){
    cout << "5. Heal.\n\n";
}
    cout << "6. Exit.\n\n";
    cin >> choice;
    if (choice == 1){
               do {
               system ("cls");
               cout << "You have chosen to fight." << endl << endl; // who they choose to fight
               cout << "Who would you like to fight?" << endl << endl;
               cout << "1. Goblin." << endl << endl;
               cout << "2. Dwarf." << endl << endl;
               cout << "3. Troll." << endl << endl;
               cout << "4. Giant." << endl << endl;
               cin >> choice;
               
                   if (choice == 1){
                         fightg();
                                 }
                                 
                   else if (choice == 2){
                         fightd();
                                 }
                                 
                   else if (choice == 3){
                         fightt();
                                 }
                                 
                   else if (choice == 4){
                         fightG();
                         }
                   
                   else {
                        cout << "That is not a choice. please try again." << endl << endl;
                        cout <<  "\nPress Enter to retry.\n\n";
                        cin.ignore();
                        cin.get();
                        
                        }
                 }  while (choice != 1 || 2 || 3 || 4);
          }
    else if (choice == 2) {
         shop();
         }
    else if (choice == 3) {
         arena();
         }
    else if (points > 0 & choice == 4){
      attpoints();
         }
    else if (health < maxhealth & choice == 5){
         heal();
         }
    else if (choice == 6){
         exit();
         done = true;
         }
    else {
                        system("cls");
                        cout << "\nThat is not a choice. please try again." << endl << endl;
                        cout <<  "Press Enter to continue.\n \n";
                        cin.ignore();
                        cin.get();
                        }
                        

} while (done != true);
}




int main (){

     cout << "Hello, Welcome." <<  endl << endl; // title screen


     cout << "What do you want your name to be?" << endl << endl;
     getline(cin,name);
     system ("cls");
     cout << "Congratulations " << name << " What do you want your class to be?"  <<  endl << endl; // this will determine base stats
     cout << "1. Warrior" <<  endl << endl;
     cout <<  "2. Mage" <<  endl << endl;
     cout <<  "3. Healer" <<  endl << endl;
     cin >>  typeofclass;
     
        
  
         if (typeofclass == 1){
            maxhealth = 50;
            system ("cls");
            yourclass = 1;
            cout <<  "You have chosen to be a Warrior.\n" <<  endl << endl; // gives stats for this person
            health = 50;
            mana = 1;
            str = 3;
            def = 3;
            }
         else if (typeofclass == 2){
            maxhealth = 25;
            system ("cls");
            yourclass = 2;
            cout <<  "You have chosen to be a Mage.\n" <<  endl << endl;
            health = 25;
            mana = 5;
            str = 1;
            def = 1;
            }
         else if (typeofclass == 3){
            maxhealth = 25;
            system ("cls");
            yourclass = 3;      
            cout <<  "You have chosen to be a Healer.\n";
            health = 25;
            mana = 4;
            str = 1;
            def = 1;
            }
         else {
            cout <<  "Sorry, thats not a right number, please try again." <<  endl;
}

      
          
      cout << "Your Stats are:" << endl << endl;
      cout << "Health " << health << endl << endl << "Mana " << mana << endl << endl;
      cout << "Strength " << str << endl << endl << "Defense " << def << endl << endl;
      cout <<  "Press Enter to continue.\n \n";
      cin.ignore();
      cin.get();
      
      mainmenu();
      
      
cin.ignore();
cin.get();





}



void shop(){
     system ("cls");
     cout << "A work in progress" << endl;
     cout << "\nPress Enter to Go to the main menu \n";
     cin.ignore();
     cin.get();
     mainmenu();
     }
     
void rest() {
     system ("cls");
     cout << "A work in progress" << endl;
     cout << "\nPress Enter to Go to the main menu \n";
     cin.ignore();
     cin.get();
     mainmenu();
     }
void arena() {
     system ("cls");
     cout << "A work in progress" << endl;
     cout << "\nPress Enter to Go to the main menu \n";
     cin.ignore();
     cin.get();
     mainmenu();
     }
     
void attpoints(){
     bool done = false;
     while (done != true){
           if (points <= 0){
                      system ("cls");
                      cout << "You have no more Points.\n";
                      cout << "Press Enter to return to the Main Menu.\n";
                      cin.ignore();
                      cin.get(); 
                      mainmenu();
                      
                      }
     system ("cls");
     cout << "You have: " << points << " Points left.\n\n";
     cout << "Your Stats are:" << endl << endl;
     cout << "Health " << health << endl << endl << "Mana " << mana << endl << endl;
     cout << "Strength " << str << endl << endl << "Defense " << def << endl << endl;
     cout << "Would you like to:" << endl;
     cout << "\n1. Add 10 to Your Health.";
     cout << "\n2. Add 1 to Strength.";
     cout << "\n3. Add 1 to Defense.";
     cout << "\n4. Add 1 to Mana.\n";
     cout << "5. Go to main menu.\n\n";
     cin >> choice;
     cout << "\n";
         
          switch (choice){
                 case 1:
                      system ("cls");
                      points = points - 1;
                      maxhealth = maxhealth + 10;
                      health = maxhealth;
                      cout << "You added 10 to your health, Your health is now: " << maxhealth << ".\n";
                      cout << "\nPress Enter to add more.\n";
                      cin.ignore();
                      cin.get(); 
                 break;
                 
                 case 2:
                      system ("cls");
                      points = points - 1;
                      str = str + 1;
                      cout << "You added 1 to your Strength, Your Strength is now: " << str << ".\n";
                      cout << "\nPress Enter to add more.\n";
                      cin.ignore();
                      cin.get(); 
                 break;
                 
                 case 3:
                      system ("cls");
                      points = points - 1;
                      def = def + 1;
                      cout << "You added 1 to your Defense, Your Defense is now: " << def << ".\n";
                      cout << "\nPress Enter to add more.\n";
                      cin.ignore();
                      cin.get(); 
                 break;
                 
                 case 4:
                      system ("cls");
                      points = points - 1;
                      mana = mana + 1;
                      cout << "You added 1 to your Mana, Your Mana is now: " << mana << ".\n";
                      cout << "\nPress Enter to add more.\n";
                      cin.ignore();
                      cin.get(); 
                 break;
                 case 5:
                      done = true;
                 break;
                
          
                }
                 }
     cout << "\nPress Enter to Go to the main menu \n";
     cin.ignore();
     cin.get();
     mainmenu();
     }
     
     
void heal(){
     system("cls");
     health = maxhealth;
     cout << "You have chosen to heal.\n\n";
     cout << "Your health is now: " << health << ".\n\n";
     cout << "\nPress Enter to Go to the main menu \n";
     cin.ignore();
     cin.get();
     mainmenu();
     
     }
     
void exit(){
     system("cls");
     cout << "Thank you for playing: " << name << ".\n\n";
     cout << "I Hope you had a fun time playing.\n\n";
     cout << "Please come play again soon.\n\n";
     cout << "To exit, Press enter.\n\n";
     cin.ignore();
     cin.get();
     }
     

void gmelee (){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 10 + 1;
                               dmg = dmg * str;
                               dmg = dmg / glvl;
                               cout <<  "You hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
     }
     
     
void gspell(){
     system("cls");
     if (yourclass == 2){                    
                   gmagic();
                   }      
     else if (yourclass == 3){
                   gclasshealing();
          }
          
     cout << "Press Enter to continue.\n\n";

      
     }
     
     
void gmagic(){
     bool done = false;
     cout << "What Spell do you want to cast?\n\n";
     if (mana >= 0){
              cout << "1. Fireball.\n\n";
              }
              
     if (mana >= 5){
              cout << "2. FireBolt.\n\n";
              }
              
     if (mana >= 10){
              cout << "3. FrostBolt.\n\n";
              }
              
     if (mana >= 15){
              cout << "4. Lightning Strike.\n\n";
              }
              
     if (mana >= 20){
              cout << "5. LightningBolt.\n\n";
              }
              
     if (mana >= 25){
              cout << "6. SuperStrike.\n\n";
              }
     cin >> choice;
     do {
     if (mana >= 0 & choice == 1){
                done = true;
                gfireball();
                }
     else if (mana >= 5 & choice == 2){
          done = true;
                gfirebolt();
                }
                
     else if (mana >= 10 & choice == 3){
          done = true;
                gfrostbolt();
                }
                
     else if (mana >= 15 & choice == 4){
          done = true;
                glightningstrike();
                }
                
     else if (mana >= 20 & choice == 5){
          done = true;
                glightningbolt();
                }
                
                
     else if (mana >= 25 & choice == 6){
          done = true;
                gsuperstrike();
                }
                
     else {
          cout << "That is not a choice.\n\n";
          cout << "Press Enter to continue.\n\n";
          cin.ignore();
          cin.get();
          }
     }
     while (done != true);
}
     
     
void gclasshealing(){
     system("cls");
     cout << "A work in Progress.\n\n";
     cout << "Press Enter to continue.\n\n";
     cin.ignore();
     cin.get();
     }
     

void gsuperstrike(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 30 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / glvl;
                               cout <<  "You Cast a Super Strike and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void glightningbolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 25 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / glvl;
                               cout <<  "You Cast a Lightning Bolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void glightningstrike(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 20 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / glvl;
                               cout <<  "You Cast a Lightning Strike and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void gfrostbolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 15 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / glvl;
                               cout <<  "You Cast a Frostbolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void gfirebolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 10 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / glvl;
                               cout <<  "You Cast a Firebolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void gfireball(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * glvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 5 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / glvl;
                               cout <<  "You Cast a Fireball and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               goblin = goblin - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
     
     
     









void dmelee (){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 10 + 1;
                               dmg = dmg * str;
                               dmg = dmg / dlvl;
                               cout <<  "You hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
     }
     
     
void dspell(){
     system("cls");
     if (yourclass == 2){                    
                   dmagic();
                   }      
     else if (yourclass == 3){
                   dclasshealing();
          }
          
     cout << "Press Enter to continue.\n\n";

      
     }
     
     
void dmagic(){
     bool done = false;
     cout << "What Spell do you want to cast?\n\n";
     if (mana >= 0){
              cout << "1. Fireball.\n\n";
              }
              
     if (mana >= 5){
              cout << "2. FireBolt.\n\n";
              }
              
     if (mana >= 10){
              cout << "3. FrostBolt.\n\n";
              }
              
     if (mana >= 15){
              cout << "4. Lightning Strike.\n\n";
              }
              
     if (mana >= 20){
              cout << "5. LightningBolt.\n\n";
              }
              
     if (mana >= 25){
              cout << "6. SuperStrike.\n\n";
              }
     cin >> choice;
     do {
     if (mana >= 0 & choice == 1){
                done = true;
                dfireball();
                }
     else if (mana >= 5 & choice == 2){
          done = true;
                dfirebolt();
                }
                
     else if (mana >= 10 & choice == 3){
          done = true;
                dfrostbolt();
                }
                
     else if (mana >= 15 & choice == 4){
          done = true;
                dlightningstrike();
                }
                
     else if (mana >= 20 & choice == 5){
          done = true;
                dlightningbolt();
                }
                
                
     else if (mana >= 25 & choice == 6){
          done = true;
                dsuperstrike();
                }
                
     else {
          cout << "That is not a choice.\n\n";
          cout << "Press Enter to continue.\n\n";
          cin.ignore();
          cin.get();
          }
     }
     while (done != true);
}
     
     
void dclasshealing(){
     system("cls");
     cout << "A work in Progress.\n\n";
     cout << "Press Enter to continue.\n\n";
     cin.ignore();
     cin.get();
     }
     

void dsuperstrike(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 30 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / dlvl;
                               cout <<  "You Cast a Super Strike and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void dlightningbolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 25 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / dlvl;
                               cout <<  "You Cast a Lightning Bolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void dlightningstrike(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 20 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / dlvl;
                               cout <<  "You Cast a Lightning Strike and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void dfrostbolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 15 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / dlvl;
                               cout <<  "You Cast a Frostbolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void dfirebolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 10 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / dlvl;
                               cout <<  "You Cast a Firebolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void dfireball(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * dlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 5 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / dlvl;
                               cout <<  "You Cast a Fireball and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               dwarf = dwarf - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
     
     
     
     
     
     
     
     
     
     

void tmelee (){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * tlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 10 + 1;
                               dmg = dmg * str;
                               dmg = dmg / tlvl;
                               cout <<  "You hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               troll = troll - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
                               
     }
     
     
void tspell(){
     system("cls");
     if (yourclass == 2){                    
     tmagic();
                   }      
     else if (yourclass == 3){
                   tclasshealing();
          }
          
     cout << "Press Enter to continue.\n\n";

      
     }
     
     
void tmagic(){
     bool done = false;
     cout << "What Spell do you want to cast?\n\n";
     if (mana >= 0){
              cout << "1. Fireball.\n\n";
              }
              
     if (mana >= 5){
              cout << "2. FireBolt.\n\n";
              }
              
     if (mana >= 10){
              cout << "3. FrostBolt.\n\n";
              }
              
     if (mana >= 15){
              cout << "4. Lightning Strike.\n\n";
              }
              
     if (mana >= 20){
              cout << "5. LightningBolt.\n\n";
              }
              
     if (mana >= 25){
              cout << "6. SuperStrike.\n\n";
              }
     cin >> choice;
     do {
     if (mana >= 0 & choice == 1){
                done = true;
                tfireball();
                }
     else if (mana >= 5 & choice == 2){
          done = true;
                tfirebolt();
                }
                
     else if (mana >= 10 & choice == 3){
          done = true;
                tfrostbolt();
                }
                
     else if (mana >= 15 & choice == 4){
          done = true;
                tlightningstrike();
                }
                
     else if (mana >= 20 & choice == 5){
          done = true;
                tlightningbolt();
                }
                
                
     else if (mana >= 25 & choice == 6){
          done = true;
                tsuperstrike();
                }
                
     else {
          cout << "That is not a choice.\n\n";
          cout << "Press Enter to continue.\n\n";
          cin.ignore();
          cin.get();
          }
     }
     while (done != true);
}
     
     
void tclasshealing(){
     system("cls");
     cout << "A work in Progress.\n\n";
     cout << "Press Enter to continue.\n\n";
     cin.ignore();
     cin.get();
     }
     

void tsuperstrike(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * tlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 30 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / tlvl;
                               cout <<  "You Cast a Super Strike and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               troll = troll - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void tlightningbolt(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * tlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 25 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / tlvl;
                               cout <<  "You Cast a Lightning Bolt and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
                               troll = troll - dmg;
                               cout <<  "Your enemy hit you for:" <<  mdmg << endl << endl << endl;
                               cout << "To continue fighing press Enter." << endl;
                               cin.ignore();
                               cin.get();
     }
void tlightningstrike(){
     system("cls");
                               dmg = 0;
                               mdmg = 0;
                               mdmg = rand() % 10 + 1;
                               mdmg = mdmg * tlvl;
                               mdmg = mdmg / def;
                               dmg = rand() % 20 + 1;
                               dmg = dmg * mana;
                               dmg = dmg / tlvl;
                               cout <<  "You Cast a Lightning Strike and hit your enemy for: " << dmg << endl << endl << endl;
                               health = health - mdmg;
              

Took a while but I leveled up and it didn't crash. One big thing is that you have everything in one file which makes it really hard to find sections of the program.

So you could try dividing it up into headers and source files that organize the program into sections that make sense (ie spells, NPCs or other objects) and you could use classes to have monsters and the player as their own data type so it is easier to read.

I would recommend playing around with classes in a completely different program like having different shapes (rectangle and triangle) and having width height variables with an area function. And then try to implement it into a program like this. Other than that this program looks pretty good and it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.