I had a question regarding a type conversion error I encountered whilst solving a question (link at the bottom). The only difference between my AC submission and my WA submission is that in the first submission I typecasted to a double rather than a float. I would highly appreciate any clarification on why float gives an error. Thank you.
WA Submission:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long long int a,b,c,d;
cin>>a>>b>>c>>d;
if(a<=b)
cout<<b<<endl;
else
{
if(d>=c)
cout<<-1<<endl;
else
{
long long int val = c - d;
long long int f = ceil((a-b)/((float)val));
cout<<(b + (c * f))<<endl;
}
}
}
return 0;
}
AC Submission
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long long int a,b,c,d;
cin>>a>>b>>c>>d;
if(a<=b)
cout<<b<<endl;
else
{
if(d>=c)
cout<<-1<<endl;
else
{
long long int val = c - d;
long long int f = ceil((a-b)/((double)val));
cout<<(b + (c * f))<<endl;
}
}
}
return 0;
}