Before I'm stuck at home with my unbelievably slow internet connection, I had an idea for this program, and wanted to see what you guys (and girls) think. I haven't compiled or tested it since I don't have a compiler at work, but I think it will do the trick:
Code:
#include <iostream>
using namespace std;
int divide(int&, int&);
int main()
{
int num, denom;
int places; //I know ints have a limit, but I don't know what kind of variable
//to use to ensure any number can be used
cout << "Enter the numerator, denominator, and desired number of decimal places: ";
cin << num, denom, places;
cout << endl << "The answer is: " << divide(num, denom) << ".";
for (int i = 0; i !=places; ++i)
cout << divide(num, denom);
return 0;
}
int divide(int& num, int& denom)
{
int ret;
ret = denom / num;
denom = (denom - (num * ret)) * 10;
return ret;
}
I'm kind of going out on a limb since I haven't tested it, but the algorithm should be what we're looking for.