if anyone has tried the piggy bank question please see my code. i am unable to figure out the error .i have edited the code to as simple as possible
include
using namespace std;
int main()
{
int t,n,i;
int p[500],k[500];
int e,f,f1;double md,maxmd;
cin>>t;
while(t-->0)
{
i=0;
cin>>e>>f;
cin>>n;
f1=f-e;
e=0;
p[500]=0;k[500]=0;
maxmd=-100;i=0;
while(n-->0)//this loop takes the input and finds the largest weight currency index
{
cin>>p[i]>>k[i];
md=double(k[i])/double(p[i]);
if(md>maxmd)
{
maxmd=md;e=i;
}
i++;
}
md=f1/k[e];//this finds the ratio
if((md*k[e])!=f1)//if the ration is a whole number it is possible else it is not
{
cout<<"This is impossible."<<endl;
}
else{
cout<<"The minimum amount of money in the piggy-bank is "<<p[e]*md<<"."<<endl;
}
}
return 0;
}