Page 2 of 3

### Re: 12342 Tax Calculator

Posted: Tue Dec 17, 2013 2:37 am
You are using floating point with ceil and multiplying by 10.0
see: http://floating-point-gui.de/

### Re: 12342 Tax Calculator

Posted: Tue Mar 11, 2014 10:53 am
Why am I got wrong answer?

Code: Select all

``````got ACCEPTED. I used the wrong tax calculation algorithm before XD
``````

### Re: 12342 Tax Calculator

Posted: Tue Mar 11, 2014 8:05 pm
brianfry713 wrote:Don't use floating point at all in this problem.

### Re: 12342 Tax Calculator

Posted: Thu Apr 03, 2014 2:42 pm
Getting WA. Can not figure out the problem

Code: Select all

``````#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
long long amount,tax;
int tc,i;
cin>>tc;
for(i=1; i<=tc; i++)
{
//        tax = 0;
cin>>amount;
if(amount<=180000)
tax = 0;
else
{
amount -= 180000;
if(amount<=300000)
{
tax = ceil(amount*10/100);
}
else if(amount>300000 && amount <=700000)
{
//                tax = 30000;
amount -= 300000;
tax = 30000 + ceil(amount*15/100);
}
else if(amount>700000 && amount <= 1000000)
{
//                tax = 90000;
amount -= 700000;
tax = 90000 + ceil(amount*20/100);
}
else if(amount>1000000)
{
//                tax = 150000;
amount -= 1000000;
tax = 150000 + ceil(amount*25/100);
}
if(tax < 2000)
tax = 2000;
}
cout<<"Case "<<i<<": "<<tax<<endl;
}
}
``````

### Re: 12342 Tax Calculator

Posted: Thu Apr 03, 2014 11:53 pm
brianfry713 wrote:
brianfry713 wrote:Don't use floating point at all in this problem.

### Re: 12342 - Tax Calculator

Posted: Mon Sep 15, 2014 1:33 pm
brianfry713 wrote:Don't use floating point at all in this problem.
Thanks for this really key piece of advice. I wrote the program one way but changed my approach when I came here looking for test cases and saw what you'd written.

By the way, I've shared my test cases on uDebug.

### Re: 12342 - Tax Calculator

Posted: Sat Sep 20, 2014 1:36 pm
I got WA. tested all the inputs in udebug..
I've searched for AC codes in google and there are so many ac codes with double type and ceil function like my code. Then what's wrong with my code..?
Here's 2 links of AC code's:
(Links are deleted after getting ac)
Here's my code... plz help...

Code: Select all

``Got AC...``
Some other critical output can be of great help for debugging...
I'll delete the code and links aftre getting AC. thanks..

### Re: 12342 - Tax Calculator

Posted: Sun Sep 21, 2014 2:59 pm
If the calculated tax is a floating point then it must be replaced by the smallest integer greater than the payable tax.
According to problem description we must print integer greater than tax in case of floating point. So must check this case.

Code: Select all

``````  break;
}

cout<<"Case "<<++count<<": ";

if(ans<2000 && ans!=0) ans=2000;

in = ans;

if (ans - in > 1e-6) in++;

cout<<in<<endl;``````

### Re: 12342 - Tax Calculator

Posted: Mon Sep 22, 2014 4:27 pm
Thanks a lot.. I got ac...  ### Re: 12342 - Tax Calculator

Posted: Wed Sep 24, 2014 1:46 pm
Instead of checking if tax is a floating point, ceil can be used.

### Re: 12342 - Tax Calculator

Posted: Thu Sep 25, 2014 6:22 pm
can't understand y "46 no line ===> if(tax-result > 1e-6 ) result++; " is not working , here's my code

Code: Select all

``````#include <iostream>
#include <math.h>

using namespace std;

int main()
{
long long n,t,cnt;
double tax;
int result;
cin>>t;
cnt=1;
while(t--)
{

cin>>n;
if(n<=180000)
cout<<"Case "<<cnt<<": 0"<<endl;
else
{
if(n<=480000)
{
n=n-180000;
tax=((10*n)/100);

}
else if(n<=880000)
{
n=n-480000;
tax=30000+((15*n)/100);

}
else if(n<=1180000)
{
n=n-880000;
tax=30000+60000+((20*n)/100);

}
else if(n>1180000)
{
n=n-1180000;
tax=30000+60000+60000+((25*n)/100);
}

result=tax;
if(tax-result > 1e-6) result++;

if(result<2000)
cout<<"Case "<<cnt<<": 2000"<<endl;
else
cout<<"Case "<<cnt<<": "<<result<<endl;
}

cnt++;
}
return 0;
}
``````

### Re: 12342 - Tax Calculator

Posted: Fri Sep 26, 2014 1:33 am
Don't use floating point at all in this problem.

### Re: 12342 - Tax Calculator

Posted: Fri Sep 26, 2014 9:49 am
To brainfry,
can't understand, what should i use instead of floating point ?? how can obey this condition "If the calculated tax is a floating point then it must be replaced by the smallest integer greater than the payable tax." without using floating point

### Re: 12342 - Tax Calculator

Posted: Fri Sep 26, 2014 2:03 pm
Actually Brainfry is right. It is always better to avoit floating point calculation because it is very easy to get precision error or other mistakes.
For this problem to avoid floating point you could multiple by some constant number to work only with integers. You could use long long for tax and all values of tax keep multiplied by 100.

Code: Select all

``````tax= 10 * n;
..
tax = 30000 + 15 * n;
..
tax = 30000 + 60000 + 20 * n;
..
tax = 30000 + 60000 + 60000 + 25 * n;
..
if (tax % 100 == 0)
{
// answer is integer = tax / 100
// print tax / 100

} else {

// answer is floating point number = tax / 100
//  print (tax + 99) / 100;  // ceil (tax)
}``````
However I solved this problem with floating point. You must be very very careful in this case. In your code you have integer division mistake. You must convert to double to avoid integer divison. It can be done in different ways.

Code: Select all

``````tax=((10*n)/100.0);
..
tax=30000+((15.0*n)/100);
..
tax=30000+60000+(double(20*n)/100.0);
..
tax=30000+60000+60000+((double(25)*n)/100.0);``````
RedCode119 wrote:can't understand y "46 no line ===> if(tax-result > 1e-6 ) result++; " is not working
It works ok! But you can also change it to ceil

Code: Select all

``result = ceil(tax);``
Don't forget to remove your code after getting accepted. ### Re: 12342 - Tax Calculator

Posted: Sat Oct 25, 2014 11:24 pm
Hi guys,
I am getting WA consistently. I have checked Inputs frm uDebug. I found that my code doesn't allow me to work with the numbers like 10000000000 and few more like this.
How can I deal with such long floats...? Is there any way ?

Code: Select all

``````#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int main ()

{
// The Code got accepted...Thanks
// Original Code has been DELETED.

return 0;
}
``````
My code will be deleted if the code gets Accepted.