how would one update 2 values at the same time

How would one go about updating 2 values while comparing them and having to return them from a list of values for example


Player is level 1
Player needs 100 exp to reach level 2.


++PlayerLevel
works to level the level up by 1.

but i also want to pull the experience needed to reach next level from a bunch of stored const int and return the value


int PlayerExperience
int PlayerNextExperience


This is the code i have so far:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
int ExperienceCalculator()
{
	// Variables that store the experience for next level
	const int NextExperienceUp2 = 100;
	const int NextExperienceUp3 = 225;
	const int NextExperienceUp4 = 400;
	const int NextExperienceUp5 = 925; 
	const int NextExperienceUp6 = 1400;
	const int NextExperienceUp7 = 2425;
	const int NextExperienceUp8 = 3650;
	const int NextExperienceUp9 = 5675;
	const int NextExperienceUp10 = 8150;
	
	// Variables that store the total exp at next level
	const int NextExperience2 = 100;
	const int NextExperience3 = 325;
	const int NextExperience4 = 725;
	const int NextExperience5 = 1650; 
	const int NextExperience6 = 3025;
	const int NextExperience7 = 5475;
	const int NextExperience8 = 7900;
	const int NextExperience9 = 11550;
	const int NextExperience10 = 19700;
	
	// Variables that store new hit points value for next level (Base 20 + 5 per level)
	const int PlayerHitPointsUp = 5;

	// Variable that store new attack value for next level (Base 12 + 2 per level)
	const int PlayerAttackUp = 2;
	
	// Variable that store new defense value for next level (Base 6 + 3 per level)
	const int PlayerDefenseUp = 3;

	// Variable that stores new hitrate value for next level (Base 50% + 1% per level)
	const int PlayerHitRateUp = 1;

	cout << "Checking players level & experience stats.\n";
while (PlayerExperience >= PlayerNextExperience)
{
	if (PlayerExperience >= PlayerNextExperience)
	{
		cout << "Leveling up player.\n";
		++PlayerLevel;
		PlayerHitPoints = PlayerHitPoints + PlayerHitPointsUp;
		PlayerAttack = PlayerAttack + PlayerAttackUp;
		PlayerDefense = PlayerDefense + PlayerDefenseUp;
		PlayerHitRate = PlayerHitRate + PlayerHitRateUp;
		cout << "Done leveling up player.\n";
		cout << "Updating experience to next level.\n";
	}
	else
	{
		cout << "Player does not need to be leveled up.\n";
		cout << "Returning to game...\n";
		goto ENDEXP;
	}
}
ENDEXP:	
	return 0;
}
Last edited on
Use arrays:
1
2
3
4
5
const int next_exp[] = {100, 325, 725, 1650};

while(player_exp >= next_exp[player_level]){
    player_level++;
}
Well i finally did get that to work! it works great. Thanks
Topic archived. No new replies allowed.