A Practical Tax program

Source: Internet
Author: User

Program Target

This procedure is derived from a practice in C Primer Plus (fifth Edition).

  

Our goal is to create a program that is user friendly and highly secure (preventing incorrect input). In accordance with the requirements of the book, we develop pseudo-code:

Subject:

  Do Loop {

Prompt for type of rating

Judgment: Type. If it is not correct, the mark is 0

Prompt to enter amount

Judgment: Amount. If it is not correct, place the mark as 0{

Type 1: Call function output tax

Type 2: Call function output tax

Type 3: Call function Output tax

Type 4: Call function Output tax

}

Buffer adjustment

} Loop continuation condition (TAG)

function for output tax:

 If: Amount is specified below

Return: Amount * 0.15

Otherwise

Return: Regulation * 0.15 + (amount-provision) * 0.28

In order to make the interface more beautiful, we use a tab to prompt the user input, and the use of unbuffered input to achieve a certain effect, in detail, see the program code.

Program code
1#include <stdio.h>2#include <stdlib.h>3#include <conio.h>4 5 /*6 This procedure is in accordance with the 1988-year states Federal tax Schedule7 The plan is divided into four standard levies:8 single 178509 Head of household 23900Ten married Total 29750 One married divorced 14875 A each class is subject to a 15% tax in its scope, and more than the partial 28% calculation - */ -  the #defineALONE 17850.0 - #defineFam_man 23900.0 - #defineMa_tog 29750.0 - #defineMa_se 14875.0 +  - DoubleCalcDoubleMoneyDouble Base); +  A intMainintargcChar*argv[]) { at     Chartype; -     DoubleMoney ; -     intFlag =1;//Loop Marker -  -      Do{ -printf"┌─────────────┐\n" in                "│ Please select taxpayer Status: │\n" -                "│a. Single B. Head of household │\n" to                "│c. Married in total D. married divorced │\n" +                "│ Enter other content to exit │\n" -                "└─────────────┘\n" the                "user#[]\b\b"); *         //The following getche is a non-buffered input with ECHO, function prototype in Conio.h $         if((type = Getche ())! ='a'&& Type! ='b'&& Type! ='C'&& Type! ='D'){Panax NotoginsengFlag =0; -printf"\ n has exited! \ n"); the              Break; +         } A  theprintf"\ n Please enter total taxpayer property: $[]\b\b\b\b\b\b\b\b\b\b\b"); +         if(SCANF ("%LF",&Money )) { -             Switch(type) { $              Case 'a': $printf"the taxpayer needs to pay $%g taxes. \ n", Calc (Money, ALONE)); -                  Break; -              Case 'b': theprintf"the taxpayer needs to pay $%g taxes. \ n", Calc (Money, Fam_man)); -                  Break;Wuyi              Case 'C': theprintf"the taxpayer needs to pay $%g taxes. \ n", Calc (Money, Ma_tog)); -                  Break; Wu              Case 'D': -printf"the taxpayer needs to pay $%g taxes. \ n", Calc (Money, Ma_se)); About                  Break; $             } -         } -         Else{ -Flag =0; Aprintf"Data Error! \ n"); +         } the          while(GetChar ()! ='\ n');//adjusting the Read buffer -  $} while(flag); the  theprintf"\ n Thank you for using \ n"); the getch (); the  -     return 0; in } the  the DoubleCalcDoubleMoneyDouble Base){ About     return(Money <Base) ? (Money *0.15) : (Base*0.15+ (Money-Base) *0.28); the     //This function returns the correct amount of tax,? : the operator is concise and provides a memory tip: the     //is that true? Yes: no the}

Some code shows error correction:

Run results

A Practical Tax program

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.