Alright, so I'm making this game and I can't be passing all this num-with-string-with-num business around, so I've decided to simplify things with a rockin' int-to-string function so I could just pass one big string. I wrote this:
but it doesn't work and it totally should. I don't need it to work in tricky situations like < 0 or == 0 or anything like that, I know what I'll be using it for. Does anybody have an idea as to what is wrong with this code? Also, I attached a simple prog that implements this if you want to see sample output.Code:string str;
int length = 0;
for (int temp = num; temp != 0; temp /= 10) ++length;
for (int i = 1; i <= length; ++i) {
int temp = num % (i * 10);
if (i > 1) temp /= (i - 1) * 10;
str = char(temp + 48) + str;
}