Write a function that accepts a salary and returns the tax.

Write a function that accepts a salary and returns the tax.


This is a function that will accept a salary from the user and return the output tax according to the following rules:


  • No Tax for first Rs.1000
  • 5% for the second Rs.1000
  • 4% for third Rs.1000
  • 3% for the remain untaxed salary

  • For Example: If the salary is Rs.4000, then the tax is Rs.120.

    The program is given below:



    #include<iostream>
    #include<math.h>
    using namespace std;
    int main()
    {
    int sal, Tax = 0;
    cout << "Enter  your salary: ";
    cin >> sal;
    while (sal !=0)
    {
    if(sal == 0)
    {
    break;
    }
    else if(sal >= 1000 && sal <=2000)
    {
    Tax += (sal*0.04);
    }
    else if(sal >= 2000 && sal <= 3000)
    {
    Tax += (sal*0.04);
    }
    else if(sal >= 3000)
    {
    Tax += (sal*0.03);
    }
    sal/= 1000;
    }
    cout << "Tax: " << Tax << endl;
    system("pause");
    }

    Comments

    Popular posts from this blog

    Book-Shop Program using C++

    Nesting of For Loop in C/C++

    Switch statement in C/C++