Management Karbust 4913 Posted August 29, 2016 Management Share Posted August 29, 2016 (edited) 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: What do I need to change? Thanks Edited August 24, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
iltizio 218 Posted August 29, 2016 Share Posted August 29, 2016 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. 1 Link to comment Share on other sites More sharing options...
Management Karbust 4913 Posted August 29, 2016 Author Management Share Posted August 29, 2016 (edited) 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... Edited August 24, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Lazarus1988 8 Posted August 30, 2016 Share Posted August 30, 2016 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 1 Link to comment Share on other sites More sharing options...
iltizio 218 Posted August 30, 2016 Share Posted August 30, 2016 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. 1 Link to comment Share on other sites More sharing options...
Lazarus1988 8 Posted September 2, 2016 Share Posted September 2, 2016 Try with my Exp Generator (source included, Run with Windows XP compability and with Admin rights) This is the hidden content, please Sign In or Sign Up 1 Link to comment Share on other sites More sharing options...
Management Karbust 4913 Posted September 2, 2016 Author Management Share Posted September 2, 2016 (edited) I have this error when I try to compile: Edited August 24, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Management Karbust 4913 Posted September 4, 2016 Author Management Share Posted September 4, 2016 BUMP Link to comment Share on other sites More sharing options...
Premium V0iĐ 115 Posted September 5, 2016 Premium Share Posted September 5, 2016 (edited) printf("Level %2d | %-12ld | %-12ld |\n", level, total, tnl); Rewrite: printf("Level %2d | %lu | %-12ld |\n", level, total, tnl); Result: Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal 1 Link to comment Share on other sites More sharing options...
Management Karbust 4913 Posted September 5, 2016 Author Management Share Posted September 5, 2016 (edited) 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: Eishhh Thank you very much <.< I didn't even remembered of that little detail Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now