Ask coding questions

← Back to all posts
How do I make a variable number raise after something changes in C++?
LoveFromSkyy (137)

I want to make a system where after the player levels up, the amount of XP required to level up goes up. How could I do this? Any example helps!

Answered by RYANTADIPARTHI (6018) [earned 5 cycles]
View Answer
Comments
hotnewtop
RYANTADIPARTHI (6018)

use ++ in front of the var

LoveFromSkyy (137)

Can you write a small program that could help me see how to do that? I don't understand.
@RYANTADIPARTHI

RYANTADIPARTHI (6018)

@LoveFromSkyy

variable = 10
variable++

like that.

LoveFromSkyy (137)

So it would go up by 10 each time it reached 10?

@RYANTADIPARTHI

RYANTADIPARTHI (6018)

@LoveFromSkyy it would go up. but for reaching ten, you need to make an if statement.

LoveFromSkyy (137)

How would I make it go up by 10?
I'm slow sorry for wasting your time.
@Coder100

LoveFromSkyy (137)

I'm getting somewhere but I need to get further, theplayer levels up every 200 XP but I want to make the requirements for leveling up higher.
Here is some of my code:

// Requirements for leveling up
int LvlUpReq(int XP, int Lvl){
	int LvlUpReq;
	LvlUpReq = 100;

	if(XP >= LvlUpReq){
		LvlUpReq++;
	}

	return (LvlUpReq);
}

int LvlUp(int XP, int Lvl){
    Lvl += XP / LvlUpReq(XP, Lvl);
    return Lvl;
}

Whats wrong with it?
@RYANTADIPARTHI

RYANTADIPARTHI (6018)

@LoveFromSkyy it seems you didn't assign XP to anything.

LoveFromSkyy (137)

I did
Somewhere else in the program, here is the other part where I NEED that LvlUpReq

void GameMenu(){
int XP;
int Lvl;
	struct Attacks sword;
	struct Hero player;
	string gameMenuChoice;


		string username;
		string password;
		


	cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
	cout << "~~~~~~~+~~~~~~~~~~~~~~+~~~~~~~~~~~~~~+~~~~~~~~~~~~~~+~~~~~~~LEGEND!~~~~~~~+~~~~~~~~~~~~~~+~~~~~~~~~~~~~~+~~~~~~~~~~~~~~+~~~~~~~\n\n\n\n";
	cout << username << "\n\n";
	Lvl = LvlUp(XP, Lvl);
	cout << "XP: " << XP << endl;
	cout << "Level: " << Lvl << endl;
	cout << "(a) Play Level\n";
	cout << "(b) Exit\n";
	cin >> gameMenuChoice;
	if(gameMenuChoice == "a"){
		LevelStart(XP, Lvl);
	}
	if(gameMenuChoice == "b"){
		cout << "Game EXITED\n";
		Menu();
	}

}

@RYANTADIPARTHI

LoveFromSkyy (137)

Nevermind, I know what I gotta do.
Thanks for helping!
@RYANTADIPARTHI

RYANTADIPARTHI (6018)

@LoveFromSkyy oh ok. no problem. Glad to hear it.

Coder100 (18819)

easy, use an assignment operator. Do you need to take a c++ tutorial?

int xp = 0;
xp += 10;

as you can see the xp will increase by 10