Ask coding questions

← Back to all posts
Help with C++ program.
LoveFromSkyy (137)

Here I am again. Asking another question about my program. My goal right now is to make it so that the player's XP clears after they level up
Here is a section of my code:

int XpClear(int XP, int Lvl){
	int XpClear;
	
	if(&LvlUp){
		XP = 0;
		return (XpClear);
	}
	return (XpClear);
}
Comments
hotnewtop
Coder100 (18818)

what part isn't working? It appears you are already making it clear

also why are you using the address to see if the user has leveled up?

And why not send repl lol

KENNETHTRIPP (51)

If I had to guess, I would say that you are returning the wrong variable. I don't know much C++, but when you call the function you could say XP = XpClear(XP, Lvl); assuming you named both of those variables XP and Lvl.

WILLIAMBAEWER (116)

you could do this:
if (XP >= 100){ //im going to assume 100 xp is needed to LVL up
/ if you want it set back to 0 / XP -= XP;
/ if you want the left over XP to carry over to the next LVL /
XP -= 100;
LVL++;
}

hope this helps

WILLIAMBAEWER (116)

if you want it in a function you can always just change it to do that too :)