since you can't use strings -or rather not allowed to-, i bet you're solving a homework.
anyway, this is the code for integers, you should convert it to work with floats yourself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// pre-condition: digits is large enough to hold each digit in a cell.
// post-condition: each cell of digits contains the corresponding digit of target.
void splitIntoDigits(int target , int digits[])
{
int oneDigit = target;
int degree = 0;
int maxDegree;
for( maxDegree = 0; oneDigit ; oneDigit/=10 , maxDegree++) ; //find how many digits is in the number.
for(int i=0 ; i<maxDegree ; i++) //begin splittin the target.
{
oneDigit = target; // make temp the current value of target.
for(degree = 0 ; oneDigit >= 10 ; oneDigit/=10 , degree++); // determine the last digit and its degree.
digits[i] = oneDigit; // assign the digit to the corresponding cell.
target -= (digits[i]* std::pow(10.0,degree)); // delete the last digit from target.
}
}
Manipulating the float data and keeping it unchanged is almost impossible especially for float of more decimals. Even using the stringstream doesn't help to keep the float from being changed. To keep the data unchanged, use string.