Jump to content

[SOLVED] Help with formula + math calc


godsent

Recommended Posts

Im trying rebuild formula from java to php, and im not going very well. I don't know what im doing wrong.

 

My PHP verssion:

function getLevelForXP($exp) {
	$points = 0;
	$output = 0;
	for ($lvl = 1; $lvl < 100; ++$lvl) {
	$points += floor( $lvl + 300.0 * pow(2.0, $lvl / 7.0));
	$output = floor($points / 4);
		if (($output - 1) >= $exp) {
			return $lvl;
		}
	}
}

 

Real java verssion:

public static int getLevelForXP(int exp) {
	int points = 0;
	int output = 0;

	for (int lvl = 1; lvl < 100; lvl++) {
	points += Math.floor((double) lvl + 300.0 * Math.pow(2.0, (double) lvl / 7.0));
	output = (int) Math.floor(points / 4);
		if ((output - 1) >= exp) {
			return lvl;
		}
	}
	return 99;
}

 

If you know please help me out

Link to comment
https://forums.phpfreaks.com/topic/139257-solved-help-with-formula-math-calc/
Share on other sites

	function getLevelForXP($exp) {
	$points = 0;
	$output = 0;
	for ($lvl = 1; $lvl < 100; $lvl++) {
	$points += floor( $lvl + 300.0 * pow(2.0, $lvl / 7.0));
	$output = floor($points / 4);
		if (($output - 1) >= $exp) {
			return $lvl;
		}
	}
	return 99;
}

looks good i only added the return and move the ++ in the for loop

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.