ok here is the deal, i am making a role playing game that has a step by step battle system. it was working until i decided to make a new function called gameplaychoice. now whenever i call to the battle function the progam just skips that line and goes to the next thing in the program. here is the code i got so far, gope you guys can see the problem cus i can't. Any help would be greatly appreciated!!!

#pragma hdrstop
#include <condefs.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

//---------------------------------------------------------------------------
#pragma argsused
void gameplaychoice (int & hp, int & gp, int & exp, int & agilitylvl, int &  lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & dammage, int & def, int chp, int cgp, int cdammage, int cexp,char *name, int & nextlevel, int & maxhp, char *nextweapon, int & blocked, int & level, char *town);
void attack (int & hp, int dammage, int def, int & chp, int cdammage, char *name, int & gp, int cgp, int & nextlevel, int & exp, int cxp, int maxhp);
void usepotion (int & lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & hp, char *name, int maxhp);
void battle (int & hp, int & gp, int & exp, int & agilitylvl, int &  lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & dammage, int & def, int chp, int cgp, int cdammage, int cexp,char *name, int & nextlevel, int & maxhp, char *nextweapon, int & blocked, int & level);
int main(int argc, char **argv)
{
// charecter stuff
int maxhp;
int hp;
int gp=120;
int exp=0;
int nextlevel=80;
int level=1;
int agilitylvl=0;
int def=0;
int dammage;
// items
int lvl1potions=0;
int lvl2potions=0;
int lvl3potions=0;
int demonpotions=0;
int secretitems=0;
// misc
int score=0;
int charecter;
int hplost;
int choice;
int blocked=0;
    cout << "A role playing game by Nate Nelson" << endl << endl;
    cout << "choose your character" << endl;
    cout << "1: Barbarian" << endl;
    cout << "2: Wizard of The Old Teachings" << endl;
    cout << "3: Gnome" << endl << endl;
    cin >> charecter;
        if (charecter == 1){
            cout << "You have chosen the nobelist and fiercest warrior in all the land, Abdazar!" << endl;
            cout << "the time has now come to choose you mode of battle." << endl << endl;
            cout << "Press any key to continue..." << endl << endl;
            getch();
            cout << "1: I would like to fight with a Giant Axe." << endl;
            cout << "2: I would like to fight with a Sword and Shield." << endl;
            cin >> choice;
                if (choice == 1){
                cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
                    hp = 50;
                    maxhp = 50;
                    def = 2;
                    cout << "Your weapon shall be an Axe like tree root." << endl << endl;
                    cout << "As your adventure begins you decide to randomly choose a direction" << endl;
                        cout << "You have stumbled upon a Goblin Warrior, he has spoted you and" << endl;
                        cout << "wishes to fight!" << endl;
                        cout << "You Valiantly fight the monster for your life." << endl << endl;
                        //this is where battle sounds or music is played
                        dammage = 10;
                        int goblinhp = 20;
                        int goblingp = 20;
                        //1st attack
                        hplost = hp;
                        goblinhp = goblinhp-10;
                        hp = hp-5+def;
                        goblinhp = goblinhp-10;
                        hp = hp-5+def;
                        hplost = hplost-hp;
                        gp = gp+goblingp;
                        hp = hp+5;
                        exp = exp + 20;
                        cout << "you have fought valiently and killed the beast!" << endl;
                        cout << "your Hit points are now at " << hp << "." << endl;
                        cout << "you lost " << hplost << " hit points, but gain " << "5" << " life back from a potion the goblin had." << endl;
                        cout << "you have gained " << exp << "/" << nextlevel << " till your next level." << endl;
                        cout << "you have gained " << goblingp << " GP from the goblin.  Your GP is at " << gp << "." << endl << endl;
                        getch();
                        gameplaychoice ( hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, 20, 20, 5, 20, "Goblin Warrior", nextlevel, maxhp, "large stick with a sharp rock tied to the end of it", blocked,  level, "Falador");
                                //display a:\battle340.jpeg here
                                cout << "Goblin Warlord: I hear you have been harrassing my goblin troops!" << endl << endl;
                                cout << "Abdazar: yeah i have been training with your troops, but i haven't been Harrassing them!" << endl << endl;
                                cout << "Goblin Warlord: That's not the way I heard it, prepare yourself for revenge!" << endl << endl;
                                cout << "Abdazar: Alright if it is a battle you want, a battle you shall have." << endl << endl;

                                blocked = 0;
                                nextlevel = nextlevel + 200;
                                battle (hp, gp, exp, agilitylvl,  lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, 200, 200, 14, 200, "Goblin Warlord", nextlevel, maxhp, "A Gothic Ancents Axe" , blocked, level);
                                cout << "The Goblin Warlord in, return for mercy, gives you the Ring of Agility!" << endl << endl;
                                cout << "As you slowly slide the ring over your knuckle, you seem to notice " << endl << "things a little faster and react with better timeing." << endl << endl;
                                cout << "your agility level has risen by 3 points!!!" << endl;








                }
getch ();
        }
        return 0;
}
void battle (int & hp, int & gp, int & exp, int & agilitylvl, int &  lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & dammage, int & def, int chp, int cgp, int cdammage, int cexp,char *name, int & nextlevel, int & maxhp, char *nextweapon, int & blocked, int & level)
{
int choice;
int blockyesno;
int attackedxtimes=0;
    if (exp >= nextlevel) {
        cout << "you have gained enough expierience to level up!!!" << endl << endl;
        exp = 0;
        nextlevel = nextlevel*2;
        maxhp = maxhp * 1.5;
        def = def + 3;
        hp = maxhp;
        agilitylvl++;
        level++;
        dammage = dammage+5;
        cout << "your max hp is now " << maxhp << endl;
        cout << "your defense is now " << def << endl;
        cout << "your agility level is now " << agilitylvl << endl;
        cout << "you find a new weapon on " << name << ". you decide to use this instead of your old weapon." << endl;
        cout << "your weapon shall now be a " << nextweapon << endl << endl;
        level++;
        return;
    }
    if (chp || hp <=0){
        return;
    }
cout << "what should i do?" << endl << endl;
cout << "1: Attack" << endl;
cout << "2: Use potion" << endl;
cout << "3: Attempt to block" << endl;
cin >> choice;
    if (choice == 1){
        attackedxtimes++;
        if (attackedxtimes  != 2 &&attackedxtimes != 5){
            if (attackedxtimes != 3 && attackedxtimes != 6){
                attack (hp, dammage, def, chp, cdammage, name, gp, cgp, nextlevel, exp, cexp, maxhp);
                if (chp && hp > 0){
                    battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
                }
            }

        }
        if (attackedxtimes == 2 || attackedxtimes == 5) {
            attack (hp, dammage, def, chp, cdammage, name, gp, cgp, nextlevel, exp, cexp, maxhp);
                if (chp && hp > 0){
                    battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
                }
            cout << name << " apears to be getting ready for some sort of special attack." << endl << endl;
        }
        if (attackedxtimes == (3 || 6)) {
            cdammage = cdammage*2;
            attack (hp, dammage, def, chp, cdammage, name, gp, cgp, nextlevel, exp, cexp, maxhp);
            cdammage = cdammage/2;
                if (chp && hp > 0){
                    battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
                }
        }
    }
    else if (choice == 2){

        usepotion (lvl1potions, lvl2potions, lvl3potions, demonpotions, hp, name, maxhp);
        if (chp && hp > 0){
        battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
        }
    }
    else if (choice == 3){
        blockyesno = rand() % 100 + 1;
            if (blockyesno <= (agilitylvl*10)){
                cout << "all dammage was successfully blocked this turn!" << endl << endl;
                cout << "Abdazar" << "              " << name << endl;
                cout << hp << "                      " << chp << endl << endl;
                blocked++;
                battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
                getch();
            }
            else if (blockyesno >= ((agilitylvl*10)+1)){
                cout << "you accedentally take a wrong step as you attempt to block and still take" << endl <<" dammage."<< endl << endl;
                hp = hp - cdammage;
                cout << "Abdazar" << "              " << name << endl;
                cout << hp << "                      " << chp << endl << endl;
                getch();
                battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
            }

    }





}


void usepotion (int & lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & hp, char *name, int maxhp)
{

int potionchoice;
    if (lvl1potions == 0 && lvl2potions == 0 && lvl3potions == 0 && demonpotions == 0) {
        cout << "you have no potions, quick pick a battle move before " << name << " attacks you!" << endl;
        return ;
    }

cout << "Use which potion?" << endl << endl;
    if (lvl1potions >= 1) {
        cout << "1: level 1 potion" << endl;
    }
    if (lvl2potions >= 1){
        cout << "2: level 2 potion" << endl;
    }
    if (lvl3potions >= 1) {
        cout << "3: level 3 potion" << endl;
    }
    if (demonpotions >= 1) {
        cout << "4: Demonic potion" << endl;
    }
cin >> potionchoice;
    if (potionchoice == 1) {
        lvl1potions = lvl1potions-1;
        hp = hp + 20;
        cout << "you have gained 20 hp, your hp is now at " << hp << endl << endl;
            if (hp > maxhp ){
                hp = maxhp;
            }
    }
    else if (potionchoice == 2) {
        lvl2potions = lvl2potions - 1;
        hp = hp + 30;
        cout << "you have gained 30 hp, your hp is now at " << hp << endl << endl;
            if (hp > maxhp ){
                hp = maxhp;
            }
    }
    else if (potionchoice == 3) {
        lvl3potions = lvl3potions - 1;
        hp = hp + 40;
        cout << "you have gained 40 hp, your hp is now at " << hp << endl << endl;
            if (hp > maxhp ){
                hp = maxhp;
            }
    }
    else if (potionchoice == 4) {
        demonpotions = demonpotions - 1;
        hp = hp + 120;
        cout << "you have gained 120 hp, you hp is now at " << hp << endl << endl;
            if (hp > maxhp ){
                hp = maxhp;
            }
    }
}

void attack (int & hp, int dammage, int def, int & chp, int cdammage, char *name, int & gp, int cgp, int & nextlevel, int & exp, int cxp, int maxhp)
{
int hplost;
hplost = hp + def;
chp = chp - dammage;
int won;
    if (chp <= 0 ) {
        won = 1;
        cout << "You are victorious!!!" << endl << endl;
        exp = exp + cxp;
        hplost = hplost - hp;
        hp = hp + cdammage;
        gp = gp + cgp;
        cout << "you lost " << hplost << " hit points, but gain " << cdammage << " life back from a potion the " << name << " had." << endl;
        cout << "your Hit points are now at " << hp << "." << endl;
        cout << "you have gained " << exp << "/" << nextlevel << " till your next level." << endl;
        cout << "you have gained " << cgp << " GP from the " << name << ".  Your GP is at " << gp << "." << endl << endl;
        return;
    }
hp = hp - cdammage;
    if (hp <= 0 ) {
        hplost = hplost - hp;
        cout << "you have " << exp << "/" << nextlevel << " till your next level." << endl;
        cout << "you have gained 0 " << " GP from the " << name << "  Your GP is at " << gp << "." << endl << endl;
        cout << "the " << name << " shows you great mercy and spares your life. Your life is now at " << maxhp << "." << endl;
        hp = maxhp;
        return;

    }
            if (won == 1) {
                hp = hp + cdammage;
            }
cout << "Abdazar" << "              " << name << endl;
cout << hp << "                      " << chp << endl << endl;

}
void gameplaychoice (int & hp, int & gp, int & exp, int & agilitylvl, int &  lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & dammage, int & def, int chp, int cgp, int cdammage, int cexp,char *name, int & nextlevel, int & maxhp, char *nextweapon, int & blocked, int & level, char *town)
{
int attackedmonsters=0;
int choice;
cout << "What would you like to do now then?" << endl << endl;
    if (attackedmonsters < 5){
    cout << "1: Look for a training partner." << endl;
    }
cout << "2: Goto " << town << "." << endl << endl;
cin >> choice;
    if (choice == 1){
        attackedmonsters++;
        battle (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked, level);
        gameplaychoice (hp, gp, exp, agilitylvl, lvl1potions, lvl2potions, lvl3potions, demonpotions, dammage, def, chp, cgp, cdammage, cexp, name, nextlevel, maxhp, nextweapon, blocked,  level, town);
    }
    else if (choice == 2){
        return;
    }


}
void gameplaychoice (int & hp, int & gp, int & exp, int & agilitylvl, int &  lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & dammage, int & def, int chp, int cgp, int cdammage, int cexp,char *name, int & nextlevel, int & maxhp, char *nextweapon, int & blocked, int & level, char *town);
void attack (int & hp, int dammage, int def, int & chp, int cdammage, char *name, int & gp, int cgp, int & nextlevel, int & exp, int cxp, int maxhp);
void usepotion (int & lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & hp, char *name, int maxhp);
void battle (int & hp, int & gp, int & exp, int & agilitylvl, int &  lvl1potions, int & lvl2potions, int & lvl3potions, int & demonpotions, int & dammage, int & def, int chp, int cgp, int cdammage, int cexp,char *name, int & nextlevel, int & maxhp, char *nextweapon, int & blocked, int & level);

Have you considered simplifying your code by using a couple of structs? Personally, I'd create a structure containing the various attributes (hp, maxHp, potions, etc), then just pass that single structure around. That should definitely help on future typos when calling functions.

void battle 
<snip>
    if (exp >= nextlevel) {
   <snip>
        return;
    }
    if (chp || hp <=0){
        return;
    }
<snip>
}

I noticed you have 3 return paths. 1 is if you move up to the next level, 2 if chp > 0 OR you're dead, and 3, you make it through the entire function. In general, it's good programming practice to eliminate multiple return paths. Why? It helps with clarifying when and why you're returning. Sometimes, it's necessary, but be careful when you do that as it can confuse you when debugging. My guess is chp > 0, so you're immediately returning from the battle call. (I could be totally off my rocker since I didn't really want to read through, in detail, that entire code snippet).

The easiest way for you to figure that out is to use a debugger and put break points at or just before your return statements. In the absence of a debugger, you can also print out unique strings to tell you where you are in your code. Assuming my above is correct, you may try something like: printf( "inside if( chp || hp <= 0). chp [ %d ], hp [ %d ]\n", chp, hp );

Finally, I didn't discover this nifty little feature for years. C/C++ has several macro's available for use: __FILE__ and __LINE__. __FILE__ is a string telling you what the current filename is. __LINE__ is an integer telling you what line number you're currently on. Using those, the above printf would become: printf( "[%s][%d] inside if( chp || hp <= 0). chp [ %d ], hp [ %d ]\n", __FILE__, __LINE__, chp, hp );

Using those helps me when I'm using the same string in multiple places, but want to figure out which of those strings it really without adding all kinds of extra debug code.

Hope that helps some,
-JB

> Have you considered simplifying your code by using a couple of structs?
Have you considered the possibility that this thread is 2 YEARS old, and that the OP has probably moved on.

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.