Jump to content

Exp Generator Problem


Recommended Posts

  • Management

Hello

I'm trying to do a exp table generator, but on level 250 the exp goes negative

Code:

#include <math.h>
#include <stdio.h>
#include <conio.h>
 
int main()
{
	unsigned int total = 0;
	int level;

	unsigned int tnl = 300;
 
	double factor = 2.1;
 
	int levels = 250;
 
	for (level = 1; level <= levels; level++)
	{    
		printf("Level %2d  |  %-12ld |  %-12ld |\n", level, total, tnl);
		total += tnl;
		tnl = levels * (1 + pow(level, factor));
	}
 
	getch();
}

Error:

c98e8c57cd3a4258887e2667607e5f71.png

What do I need to change?

Thanks

Edited by Metin2 Dev
Core X - External 2 Internal

raw

raw

Link to comment
Share on other sites

It's an overflow .https://en.m.wikipedia.org/wiki/Arithmetic_overflow

It's the basic of developing. If you want to develope something you need to study the base. On YouTube you can find some lessons to learn the basic thing to know before starting programming. You can also study on books.

 

To resolve this simple problem, declare a variable greater than int: long int.

 

This is the wrong and less optimal method to create an exp table. Use a more complex function (second grade) with excel, helping with graphs.

 

  • Love 1
Link to comment
Share on other sites

  • Management

I already tried with unsigned int, unsigned long, unsigned long int, long long int, unsigned long long int, and none has worked...

I know its a overflow, but I don't know how to solve, I already tried the bigger types and still the same error...

0faaf9d49f8c4f2c810ac94cbd22da0d.png

Edited by Metin2 Dev
Core X - External 2 Internal

raw

raw

Link to comment
Share on other sites

Tried with abs(int x) ?

And this is my personal opinion, and question.

Why you use so high values? Currently this looks... not nice. When I check the level how many exp I have to gain I can easly got lost when I see

189332244 or something like that. Try to write it that exp will looks like that 10000000.

Write some constant base exp and increase it by some cool formula

  • Love 1
Link to comment
Share on other sites

  • Management
32 minutes ago, V0iĐ said:

printf("Level %2d  |  %-12ld |  %-12ld |\n", level, total, tnl);

Rewrite:

printf("Level %2d  |  %lu |  %-12ld |\n", level, total, tnl);

 

Result:

axFkpPi.png

Eishhh

Thank you very much <.<

I didn't even remembered of that little detail ^_^

Edited by Metin2 Dev
Core X - External 2 Internal

raw

raw

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / 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.