0

Why the code(A) is producing is output in terms of exponential for large values.

for eg:-input(in)=1400000 output:-1.2375e+006(without using variable k).

An integer "in" denoting income in rupees is given. Find net income. The net income is calculated by subtracting the total tax (also called tax reduction) from the total income.

long long int in;
        cin>>in;
        long long int a,b,c,d,e;
        a=(250000)*0.05;
        b=(250000)*0.10+a;
        c=(250000)*0.15+b;
        d=(250000)*0.20+c;
        e=(250000)*0.25+d;

code without using variable (long long)k

code(A)

        cout<<1LL*in<<endl;
        else if(in<=500000)
        cout<<1LL*(in-((in-250000)*0.05))<<endl;
        else if(in<=750000)
        cout<<1LL*(in-a-((in-500000)*0.10))<<endl;
        else if(in<=1000000)
        cout<<1LL*(in-b-((in-750000)*0.15))<<endl;
        else if(in<=1250000)
        cout<<1LL*(in-c-((in-1000000)*0.20))<<endl;
        else if(in<=1500000)
        cout<<1LL*(in-d-((in-1250000)*0.25))<<endl;
        else
        cout<<1LL*(in-e-((in-1500000)*0.30))<<endl;

whereas input(in)=1400000 output:-1237500(using variable (long long)k)

code using (long long)k

code(B)

        long long int k;
        if(in<=250000)
          k=in;
        else if(in<=500000)
          k=(in-((in-250000)*0.05));   
        else if(in<=750000)
          k=(in-a-((in-500000)*0.10));
        else if(in<=1000000)
          k=(in-b-((in-750000)*0.15));
        else if(in<=1250000)
          k=(in-c-((in-1000000)*0.20));
        else if(in<=1500000)
          k=(in-d-((in-1250000)*0.25));
        else 
          k=(in-e-((in-1500000)*0.30));
        cout<<k<<endl;

  • 3
    That’s the default format. You can change it to something else you want if you don’t want it that way – Sami Kuhmonen Feb 16 '20 at 20:19
  • Does this answer your question? [How to make C++ cout not use scientific notation](https://stackoverflow.com/questions/5212018/how-to-make-c-cout-not-use-scientific-notation) – Tarek Dakhran Feb 16 '20 at 21:52

0 Answers0