Jump to content

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
https://metin2.dev/topic/13216-exp-generator-problem/
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
https://metin2.dev/topic/13216-exp-generator-problem/#findComment-75636
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
https://metin2.dev/topic/13216-exp-generator-problem/#findComment-75637
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
https://metin2.dev/topic/13216-exp-generator-problem/#findComment-75643
Share on other sites

And you could also have some problem with game if you use so higth values. Listen me: don't use a C++ programm to do that and use excel or similar to calculate the correct mathematic function of second grade with maximum value 2^31-1. 

 

  • Love 1
Link to comment
https://metin2.dev/topic/13216-exp-generator-problem/#findComment-75645
Share on other sites

  • Premium

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

Rewrite:

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

 

Result:

axFkpPi.png

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
https://metin2.dev/topic/13216-exp-generator-problem/#findComment-76044
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
https://metin2.dev/topic/13216-exp-generator-problem/#findComment-76048
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

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.