Calculate Personal income Tax! Switch statement

Source: Internet
Author: User

The purpose of the machine: learn to use circular control statements to solve practical problems

On the machine content: Write a multi-branch selection structure program, according to individual monthly income, calculate the tax payable and after-tax income.

/*

* Copyright (c) 2012, Computer College, Yantai University

* All rights reserved.

* Author: Xu Benxi

* Date of Completion: October 27, 2012

* Version Number: v1.0

* Input Description: Total monthly income of individual

* Problem Description: As of September 1, 2011, China's adjusted personal income tax collection method, the starting point is 3500 yuan, the excess part according to the following 7 levels of calculation:

* 1 over 0 to 1500 tax rate 3% calculating quickly deduction number 0

* 2 part of the tax rate of $1500 to 4500 $10% calculating quickly deduction of 105

* 3 part of the tax rate of $4500 to 9000 $20% calculating quickly deduction of 555

* 4 part of the tax rate of $9,000 to 35,000 $25% calculating quickly deduction of 1005

* 5 part of the tax rate of $35,000 to 55,000 $30% calculating quickly deduction of 2755

* 6 part of the tax rate of $55,000 to 80,000 $35% calculating quickly deduction of 5505

* 7 more than 80,000 of the tax rate 45% calculating quickly deduction 13505

* Personal Income tax = (total income-3500)

* Tax rate-calculating quickly deduction number

* Program output: Tax payable and after-tax income (required to complete the program design with a nested IF statement)

* Problem Analysis:

* Algorithm Design:

#include <iostream> using namespace std;
	int main () {double dsalary,dtax,dnetincome,dvalue,drate, doffset;//salary, payment amount, after-tax surplus, taxable amount, tax rate, count deduction. int istep;
		Tax Grade cout<< "Please input the total revenue of this month (yuan):";
		cin>>dsalary;
		dvalue=dsalary-3500;
		if (dvalue<=0) cout<< "dtax=0 yuan";
		else {if (dvalue<=1500) istep=1;
		else if (dvalue<=4500) istep=2;
		else if (dvalue<=9000) istep=3;
		else if (dvalue<=35000) istep=4;
		else if (dvalue<=55000) istep=5;
		else if (dvalue<=80000) istep=6;
		else if (dvalue>80000) istep=7;
		Switch (istep) {case 1:drate=0.03,doffset=0;break;
		Case 2:drate=0.1,doffset=105;break;
		Case 3:drate=0.2,doffset=555;break;
		Case 4:drate=0.25,doffset=1005;break;
		Case 5:drate=0.3,doffset=2755;break;
		Case 6:drate=0.35,doffset=5505;break;
		Case 7:drate=0.45,doffset=13505;break;}
		Dtax=drate*dvalue-doffset;
		Dnetincome=dsalary-dtax;
		cout<< "Taxable" <<dTax<< "Yuan" <<endl; cout<< "remaining after tax" <<dnetincome<< "Yuan" <<endl;
return 0;

	
 }


Run Result:

Experience: Practice using Switch statements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.