int main()
{
static short multiplycounter;
static short dividecounter;
double decimal;
int rdecimal;
cin >> decimal;
rdecimal = int(decimal);
cout << setprecision(10) << decimal << endl << rdecimal << endl;
if(rdecimal % 1 != 0)
{
while(rdecimal % 1 != 0)
{
if(rdecimal % 1 == 0) { break; }
multiplycounter = 0;
decimal = decimal * 10;
}//loop
}//if statement
cout << decimal;
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
Basically, I am trying to create a calculator that will take a number with a decimal part and change it into its fraction equal. I am having problems, though because I am trying to take the decimal number the use inputs, and multiplying it by ten until it has no decimal on the end. For example, if the user entering 12.745, I would multiply it by ten three times to get 12,745, and from there I could put that number over a denominator, and I could easily come up with that denominator by using the original number. For now at least, I don't have any problems there. But the real problem I'm having is how can I tell once I can stop multiplying the number by ten? My compiler complains when I try to use the modulus with a double or floating point value, and if I type cast to int, well, that obviously won't work either, because the decimal part is destroyed. What am I to do? :'(