c# runescape xperience formula

A place to discuss development on the Microsoft .NET framework platform utilizing languages such as C#, Visual Basic, J# and Managed C++

Moderators: IRC Operators, Support Team

mozley
Newbie
Newbie
Posts: 1
Joined: Wed Oct 06, 2010 5:55 am

c# runescape xperience formula

Postby mozley » Wed Oct 06, 2010 6:01 am

int experienceForLevel(int level)
{
if (level <= 0)
{
return 0;
}

double total = 0;
for (int i = 1; i < level; i++)
{
total += floor(i + 300 * pow(2, i / 7.0));
}

int tenative = floor(total / 4);
return tenative;
}

I use the above code to calculate the amount of experience for any given level. What would the formula or algorithm need I use for the other way around. I put in an experience amount and it gives me a number which would be rounded down to give me a letter?
Patje
mIRC Guru
mIRC Guru
Posts: 1253
Joined: Sun Dec 17, 2006 2:56 pm
Location: Netherlands

Re: c# runescape xperience formula

Postby Patje » Thu Oct 07, 2010 11:21 am

You will have to use the same loop to loop through all levels and how much experience they require. If the given exp is less than the exp of the level you are at at that point, the level is (level - 1).

Code: Select all

int expToInt(int exp) {
  double total = 0;

  for (int level = 1; total <= exp; level++) {
    total += (floor(level + 300 * pow(2, level / 7.0)) / 4);
  }

  return (level - 1)
}


I haven't tested this, but it should work.

Return to “.NET”

Who is online

Users browsing this forum: No registered users and 2 guests