So in my program, I am supposed to have the user input a base, up to base 32, and a random decimal value to be converted. So if the user entered 5 and 10, it would have to print to the screen 10 in base 5, 4, 3, and 2. However, this is my first time using dynamic allocation so I'm getting weird errors, and this is one I can't fix. (d stands for decimal value, b stands for base, arrayPtr is my dynamic allocation array)
while(d != 0 && d>b)
{
*arrayPtr = digits[(d%b)];
d = d/b;
arrayPtr++;
n++;
}
//print statement to read array backwards to give correct output
for (int i=n-1; i>=0; i--)
{
cout<<"Base "<<i <<": "*(arrayPtr+(i*sizeof(*arrayPtr)))<<" "; }
b--;
cout<<endl;
I am getting an error(invalid operands of types 'const char [3]' and 'int*' to binary 'operator*') on the line that says: cout<<"Base "<(arrayPtr+(isizeof(*arrayPtr)))<<" "; Can someone help me understand why this is happening?
arrayPtr. - kfsone": "and*(arrayPtr+(i*sizeof(*arrayPtr))). - molbdnilosizeof(*arrayPtr); the compiler will do that for you. - Pete Becker