Name: BobTheCompiler 2011-03-09 17:45
Fellow /prog/rammers, I come to you with something I'm trying to clean up. Ages ago, I created an excel spreadsheet whose sole purpose was to convert base10 number to other bases (such as base13, which allows 6 x 9 to equal 42). Did it more out of boredom/challenge than anything else.
That same boredom hit me today and I converted the equations to C++. Issue? The code is so evil is practically stares back at you, deep into your soul. The whole purpose of the code right now is to extract digits: That is if I input 1234 it will push back out 1 2 3 4. Just the single digit in a particular place.
My question is: Has anyone ever tried to create a function like this, and is there a better way I can pull this off? The meat of the function is listed below.
/* int places is set in another part of the function, and will be the total number of digits. 1234 would have places set to 4 */
while (places)
{
cout << "Place 10^" << places -1 << " Digit: " <<
((((input * 10) % (static_cast<int>(pow(base,places+1))))
/static_cast<int>(pow(base,places))) *
static_cast<int>pow(base,places)))
/static_cast<int>pow(base,places)) << endl;
places--;
}
That same boredom hit me today and I converted the equations to C++. Issue? The code is so evil is practically stares back at you, deep into your soul. The whole purpose of the code right now is to extract digits: That is if I input 1234 it will push back out 1 2 3 4. Just the single digit in a particular place.
My question is: Has anyone ever tried to create a function like this, and is there a better way I can pull this off? The meat of the function is listed below.
/* int places is set in another part of the function, and will be the total number of digits. 1234 would have places set to 4 */
while (places)
{
cout << "Place 10^" << places -1 << " Digit: " <<
((((input * 10) % (static_cast<int>(pow(base,places+1))))
/static_cast<int>(pow(base,places))) *
static_cast<int>pow(base,places)))
/static_cast<int>pow(base,places)) << endl;
places--;
}