I made this humble function to transform a string into an integer. I can't figure out how this function returns the number (that it's supposed to return) minus 1.
For example, if it has an argument of "105", it will return the number 104. There may be another way to do this easy task, but I really want to know where does my code fail in order not to make this mistake again.
It is C++
int convertnumber(string cad)
{
int e = 0;
int number = 0;
for (int i = cad.length() - 1; i >= 0; i--)
{
number += (cad[i] - '0') * (pow(10, e));
e++;
}
return number;
}