FLOW009 , Total Expenses

please help me in finding out the mistake i had done in this code ? i am continuously getting as “wrong answer” when i submit the solution, though i am able to get all outputs given in question correctly!

#include <stdio.h>

int main(void) {
// your code goes here
int t;
scanf("%d",&t);

long int p,q;
while(t--){
scanf("%ld %ld", &q,&p);
if(q>1000){
    double k = (float)p*(float)q*9/10;
    printf("%lf\n", k);
}else if(q<=1000) {
    double k= (float)p*(float)q;
    printf("%lf\n",k);}
}
return 0;

}

Thanks in advance :slight_smile:

Hey! please give the link of the problem so that I can see the problem and help you out.

Try %f instead of %lf and 0.9 instead of 9/10.

This is just a suggestion. I haven’t run your code with this change.

My AC solution : CodeChef: Practical coding for everyone

yeah it is showing as right answer now , but why so ? I mean why I am getting right answer if I use 0.9 and wrong answer if I use 9/10 ?

sorry I don’t know how to do that!

because 0.9 treated as float while 9/10 will depend on your expression and 0.9 will give exact answer while 9/10 will give you 1 as a answer in some case because it treat 9 and 10 as integer then answer will also integer.
May u understand

Yah I got your point sir but I have small query , here we got a case where we are using terminating fraction 9/10 , but for suppose if I need to take 2/3 (some non terminating fraction) then what i need to do to get right output??