In my code, I have command line arguments, and they are being passed correctly. I am converting a base 2-10 number into base 10 using coefficient base exponent form. it works on many numbers, but many others don't work. It is noticeable with you convert base 10 numbers, 3 digits, to base 10.
This is my function:
int decimal(int inbase, int dig, int argc, char *argv[])
{
int total = 0, place = dig - 1;
for(int i = 0; i < dig; i++)
{
total = total + (argv[2][place] - '0')*pow(inbase, i);
cout<<"Argv: "<<argv[2][place] - '0'<<endl;
cout<<"Power: "<<pow(inbase, i)<<endl;
cout<<"Total After: "<<total<<endl;
place--;
}
return total;
}
Argv[2] is being passed as a character sting, an example input at compiling this program is: ./a.exe 10 100 10 Expected output in base 10: 100 What I get: 99