+ 1
Why doesn't this expression work properly?
When I am giving expression as current,it gives wrong answer.But When giving expression like commented out expression.Then it gives correct result.Why don't current expression work properly? https://code.sololearn.com/cQ75957wPhfS/?ref=app
4 Antworten
+ 2
1st one total = salary+(sale*(15/100)) ;
(15/100) is done first since 15 and 100 are int, the result of that division is 0
so total will be salary + (sale * 0)
2nd one total = salary+((sale*15)/100);
(sale * 15) is done first which will give a double since sale is a double. double/100 will result in a correct division instead of 0.
+ 1
// Convert int to double
total = salary+(sale*((double)15/100));
//or
total = salary+(sale*0.15);
// Good Luck
+ 1
SoloProg could you tell me the cause?
0
sry, i don't know anything about C, but i think it can't convert int to double, i'm not sure, i dont know :v
double sale,salary,total;
scanf("%lf %lf",&salary,&sale);
total = salary+(sale*0.15);
printf("SALARY = %.2lf \n",salary);
printf("SALE = %.2lf \n",sale);
printf("TOTAL = %.2lf",total);
return total;