Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
C#
using System;

namespace tax
{
    class Program
    {
        static void Main(string[] args)
        {
            float ret;
            Console.WriteLine("Enter gross pay");
            int gross = Convert.ToInt32(Console.ReadLine());
            Program n = new Program();
            ret = n.logic(gross);
            Console.WriteLine("Tax for your gross pay is {0}", ret);
            float total = gross + ret;
            Console.WriteLine("total amount to be paid is {0}", total);
            Console.ReadKey();



        }
        public float logic(int c)
        {
            float result;
            if(c <= 100000)
            {
                result= 0;
            }
            else if((c >100000)&&(c <=300000))
            {
               result =   (c  * (15 / 100));
            }
            else if(c >300000)
            {
               result =  (c  * (28 / 100));
            }
            else
            {
                result = 0.0f;
            }
            return result;
        }
    }
}
Posted
Updated 24-Sep-15 4:59am
v2
Comments
F-ES Sitecore 24-Sep-15 11:04am    
Step through your code line by line and find out for yourself.

http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-A-Beginn

Learning to debug your code and resolve your own problems is a vital skill.
Palash Mondal_ 24-Sep-15 11:10am    
You need to provide bit more info here like what values you have passed for testing, etc.

Quote:
result = (c * (15 / 100));

Quote:
result = (c * (28 / 100));

The expressions on the right hand side of the above statements are evaluated using integer math. Change them to (for instance)
result =  (c  * (15.0f / 100));

result =  (c  * (28.0f / 100));

to force floating point evaluation.
 
Share this answer
 
Use float instead of integer!
The error by using an integer is that 15 / 100 = 0 as well as 28 / 100 = 0!

C#
public float logic(float c)
{
    float result;
    if(c <= 100000)
    {
        result= 0;
    }
    else if((c >100000)&&(c <=300000))
    {
       result =   (c  * (15f / 100f));
    }
    else if(c >300000)
    {
       result =  (c  * (28f / 100f));
    }
    else
    {
        result = 0.0f;
    }
    return result;
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900