So i haven't been coding in awhile and i just decided to try and make a game again.
nothing fancy just a simple text rpg.
here's my code so far there's a few errors and if you know how to fix them that would be great...
also i have some comments on some code, some of them things i need help with, if you know how to do them i would appreciate it.

anyway here's the code:

# include <iostream>
# include <cmath>

using namespace std;

    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;
    int typeofclass; 
    int health;
    int mana;
    int str;
    int def;
    int expe;
    int lvl1; // will require set ammount of exp.
    int lvl2; // will require set ammount of exp.
    int lvl3; // will require set ammount of exp.
    int lvl4; // will require set ammount of exp. 
    int lvl5; // will require set ammount of exp.
     
    
    
int main (){
 
     cout << "Hello, Welcome." <<  endl; // title screen
     char name [40]; // lets the players name be up to 40 characters
     int typeofclass; 
     int health;
     int mana;
     int str;
     int def;
     int exp;
     int lvl1; // will require set ammount of exp.
     int lvl2; // will require set ammount of exp.
     int lvl3; // will require set ammount of exp.
     int lvl4; // will require set ammount of exp. 
     int lvl5; // will require set ammount of exp.
     
     
     cout << "What do you want your name to be?" << endl; 
     cin >>  name;
     cout << "Congratulations " << name << " What do you want your class to be?"  <<  endl; // this will determine base stats
     cout << "1. Warrior" <<  endl;
     cout <<  "2. Mage" <<  endl;
     cout <<  "3. Healer" <<  endl;
     cin >>  typeofclass;
     system ("cls");
         if (typeofclass == 1){
            cout <<  "You have chosen to be a Warrior." <<  endl; // gives stats for this person
            health = 500;
            mana = 10;
            str = 25;
            def = 25;
            }
         else if (typeofclass == 2){
            cout <<  "You have chosen to be a Mage." <<  endl;
            health = 250;
            mana = 50;
            str = 10;
            def = 10;
            }
         else if (typeofclass == 3){
            cout <<  "You have chosen to be a Healer." <<  endl;
            health = 250;
            mana = 40;
            str = 5;
            def = 5;
            }
         else {
            cout <<  "Sorry, thats not a right number, please try again." <<  endl; 
}
      cout << "Your Stats are:" << endl;
      cout << "Health " << health << endl << "Mana " << mana << endl;
      cout << "Strength " << str << endl << "Defense " << def << endl;





system ("pause");
return 0;
}

     
     void fightg (){
     
     
              system ("cls");
                  do
                    if (health <= 0){
                    cout << "You have died." << endl; // if you died from the fight then it will return to the main menu
                    cout << "Returning to Main menu." << endl; // if not it will ignore this
                    void mainmenu();
                    }
                         cout << "You have chosen to fight a Goblin." << endl; 
                         cout << "Do you want to: " << endl;     
                         cout << "1. Fight." << endl;
                         cout << "2. Heal." << endl;
                         cout << "3. Go to Main menu." << endl;
                         cin >> choice;
                           if (choice == 1){
                               cout >> "You hit your enemy for: " >> endl;
                               // will put random numbers between 1 and 10
                               // multiply this random number Strength
                               cout >> "Your enemy hit you for:" >> endl;
                               // will do random between 1 and 20
                               // multiply this by the monsters level
                               cout >> "The Goblins health is: " >> goblin >> endl;
                               cout >> "Your health is: " >> health >> endl;
                                 }
                  while (goblin > 0){
                  exp = exp ++ 10;
                  }
}

void mainmenu (){
    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;
    
    system ("cls");
    cout << "Main menu." << endl; // Main menu
    cout << "What would you like to do?" << endl;
    cout << "1. Fight." << endl;   
    cout << "2. Go to the Shop." << endl;   
    cout << "3. Rest." << endl;   
    cout << "4. Go to the Arena." << endl;
    cin >> choice;
    if (choice == 1){
               system ("cls");
               cout << "You have chosen to fight." << endl; // who they choose to fight
               cout << "Who would you like to fight?" << endl;
               cout << "1. Goblin." << endl;
               cout << "2. Dwarf." << endl;
               cout << "3. Troll." << endl;
               cout << "4. Giant." << endl;
               cin >> choice;
               if (choice == 1){
                  void fightg();
                          }
          } 
      
    
}

Recommended Answers

All 5 Replies

What are the errors? You could also reduce the amount of variables that you have by a fair way. Instead of using "int lvl1", "int lvl2" and so on, just use an array.

Well, one thing I see right away is that you're re-declaring lots of variables.

You wrote the same variables

int expe //erase
int exp//correct

You can use the word switch and case:

void game(){

cout << "What do you want your class to be?"<<endl;
cout << "1. Warrior" << endl;
cout << "2. Mage" << endl;
cout << "3. Healer" << endl;

cin>>typeofclass;

switch(typeofclass){
	case 1:


cout << "You have chosen to be a Warrior." << endl; // gives stats for this person

health = 500;
mana = 10;
str = 25;
def = 25;

break;

case 2:

cout << "You have chosen to be a Mage." << endl;

health = 250;
mana = 50;
str = 10;
def = 10;

break;

case 3:

cout << "You have chosen to be a Healer." << endl;

health = 250;
mana = 40;
str = 5;
def = 5;

break;

default: cout<<"Sorry, thats not a right number, please try again." << endl;
}
}

Use short typeofclass instead of int typeofclass

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.