Spoj: GAMES

I’m trying to solve http://www.spoj.com/problems/GAMES/ this problem on SPOJ, but it is giving WA everytime, Can you help me about what I’m missing? Thanks
Here’s my code:

#include <iostream>

using namespace std;
#define ll long long int

ll gcd(ll a,ll b)
{
if(b==0) return a;
else return gcd(b,a%b);
}

int main ()
{

int t;

scanf("%d",&t);

while(t–)
{

double avg; 
cin>>avg;
ll l=1;
int i; ll k;
double k1;
for(i=1;i<=5;i++)
{
	k=0;
	k1=0.0;
	l=l*10;
	k=avg*l;
//	cout<<k<<endl;
    k1=avg*l;
 //   cout<<k1<<endl;
	if(k1-k<=0.00001) break;
}

ll g=gcd(k,l);
cout<<l/g<<endl;

}

return 0;
}

Avoid using float/double when accuracy is important…you are getting a WA because of the way double values are stored.
Try solving this problem without using double/float…rather use a string

Yeah, I did it using string, got AC.

//