C Language 100 Example 21 data filling errors The importance of the verification of the problem

Source: Internet
Author: User

/** * Title: Bonuses awarded by the enterprise according to the profit commission. * Profit (I) less than or equal to $100,000, the bonus can be raised 10%;* profit above 100,000 yuan, less than 200,000 yuan, less than 100,000 yuan in part by 10% commission, higher than the portion of 100,000 yuan, can commission 7.5%;*20 million to 400,000, higher than 200,000 yuan portion, can commission 5%;* Between 400,000 and 600,000 is higher than the portion of 400,000 yuan, can commission 3%;*60 million to 1 million, higher than 600,000 yuan of the portion, can commission 1.5%;* higher than 1 million yuan, more than 1 million yuan part by 1% Commission. * Enter the current month profit I from the keyboard, the total bonus should be issued? * Program Analysis: Please use the axis to demarcation, positioning. Note that the bonus definition should be defined as the growth integral type. ****/DoubleAward (Doublea) {        if(A <0)    {        return 0; }    //The system has the default conversion rules, that is, from the precision of the bottom of the conversion to high precision, to avoid the loss of precision calculation//------ ---> Unsigned --------------and unsigned long---    Doubleres =0; Doublepercent[6] = {0.1,0.075,0.05,0.03,0.015,0.01 };Doublestep[6] = {100000,100000,200000,200000,4000000,0};//The second-to-last element is filled in 4 million and results in a non-conformance with the answer.//Double Step[6] = {100000, 100000, 200000, 200000, 400000, 0}; //first consider the overflow problem    /** if (0<a <= 100000) {res = a * 1/10;        } else if (a<=200000) {res = 100000 * 1/10;    Res + = (a-100000) * 75/1000;    } else if (a<=400000) {res = a * 0.01;    } else if (a<=600000) {res = a * 0.01;    } else if (a<=1000000) {res = a * 0.01;    } else {res = a * 0.01; }    **/    /** Pseudo-process: Determine whether the above 10 does not calculate and then exit minus 100,000 of the profit minus 100,000 calculated profit hypothesis 200万190万10万 calculate profit 1.8 million 100,000 calculate profit 16.0002 billion calculate profit 14.0002 billion calculate profit 10.0004 billion calculate profit 1 million residual calculate profit last not calculate hypothesis 430,003 300.1 million calculate profit 2.3001 billion calculate profit 3 200,000 calculate profit 30,000 remaining profit <0 **/    DoubleMoney ; printf ("value passed in parameter:%lf\n", a);  for(inti =0;i<6; i++) { money= A-step[i];//The amount of money left        if(Money <=0) {res+ = A *Percent[i]; printf ("section%0.1d:%lf\n", i +1, RES);  Break; }        Else{a= Money;//the remaining amount of money is assigned to a for the next cycle of preparation            if(Step[i]! =0) {res+ = step[i] *Percent[i]; printf ("section%0.1d:%lf\n", i +1, RES); }            Else{res+ = A *Percent[i]; printf ("section%0.1d:%lf\n", i +1, RES);  Break; }                    }    }        returnRes;}DoubleAward2 (Doublei) {    //clear process-oriented processes    DoubleBonus1, Bonus2, BONUS4, BONUS6, BONUS10, bonus; Bonus1=100000*0.1; Bonus2= Bonus1 +100000*0.075; BONUS4= Bonus2 +200000*0.05; BONUS6= BONUS4 +200000*0.03; BONUS10= BONUS6 +400000*0.015; if(I <=100000) {Bonus= i*0.1; }    Else if(I <=200000) {Bonus= Bonus1 + (i-100000)*0.075; }    Else if(I <=400000) {Bonus= Bonus2 + (i-200000)*0.05; }    Else if(I <=600000) {Bonus= BONUS4 + (i-400000)*0.03; }    Else if(I <=1000000) {Bonus= BONUS6 + (i-600000)*0.015; }    Else if(i>1000000) {Bonus= Bonus10 + (i-1000000)*0.01; }        returnbonus;}

Input and output:

intMain () {printf ("The number of bits in a byte%d\n", Char_bit); printf ("The minimum value of signed CHAR =%d\n", schar_min); printf ("The maximum value of signed CHAR =%d\n", Schar_max); printf ("The maximum value of UNSIGNED CHAR =%d\n", Uchar_max); printf ("The minimum value of short INT =%d\n", shrt_min); printf ("The maximum value of short INT =%d\n", Shrt_max); printf ("The minimum value of INT =%d\n", int_min); printf ("The maximum value of INT =%d\n", Int_max); printf ("The minimum value of CHAR =%d\n", char_min); printf ("The maximum value of CHAR =%d\n", Char_max); printf ("The minimum value of LONG =%ld\n", long_min); printf ("The maximum value of LONG =%ld\n", Long_max); printf ("The maximum value of float =%f\n", Flt_max); printf ("The minimum value of float =%f\n", flt_min); printf ("The maximum value of double =%f\n", Dbl_max); printf ("The minimum value of double =%f\n", dbl_min); DoubleA;  for (;;) {printf ("your net profit is: \ n"); scanf ("%LF", &a); printf ("1 Function Profit Commission%lf\n", award (a)); printf ("2 function Profit Commission%lf\n", Award2 (a)); }return 0;}

  

C Language 100 Example 21 data filling errors The importance of the verification of the problem

Related Article

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.