Help me in solving CARCHOICE problem

My issue

My code

#include <iostream>
using namespace std;

int main() {
int t,i;
cin>>t;

for (i=1;i<=t;i++){
    
   int x1,x2,y1,y2;
   cin>> x1>>x2>>y1>>y2;
   
double a,b;
a = y1/x1;
b = y2/x2;


    
 if(a<b){
   cout<<-1<<endl; 
}    
else if(a>b){
   cout<<1<<endl; 
}    
else if(a==b) {
   cout<<0<<endl; 
}           
    
    
    
}
	return 0;
}

Problem Link: CARCHOICE Problem - CodeChef

Hi there!

I’m assuming, you want to debug your code.

Note that x1, x2, y1, y2 all are integers therefore (x1 / y1) and (x2 / y2) will also be integers.

Now, if you want their results in decimal then you have to explicitly type-cast it to double.

Here is an example,
a = 5, b = 2

// Without typecasting
c = a / b -----> c = 2

//With typecasting
c = (double) a / b -----> c = 2.5
c = a / (double) b -----> c = 2.5

So, following are changes to required to make
a = (double) y1/x1;
b = (double) y2/x2;

Hope this solve your problem.

@suvam_4002
I guess your approach to take variables as double is great but you should take all variables as double or else you have to go for type casting , if u leave it as it is and do an operation between an int and double you might loose some data which leads to incorrect ans to any one of the test cases which run behind the screen .

I have pasted my code below .
hope this helps !!
#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
double x1,x2,y1,y2;
cin>>x1>>x2>>y1>>y2;
double a1=y1/x1;
double a2=y2/x2;
if(a1==a2)
{
cout<<0<<endl;
}
else if(a1>a2)
{
cout<<1<<endl;
}
else
cout<<-1<<endl;
}
return 0;
}

Indeed, taking variables as double is the best idea. I just wanted to explain where and why his/her code failed.