Beruflich Dokumente
Kultur Dokumente
Figure 4.1 Evaluation Tree and Step-byStep Evaluation for !flag || (y + z >= x - z)
Figure 4.2 Range of True Values for min <= x && x <= max
Figure 4.4 Flowcharts of if Statements with (a) Two Alternatives and (b) One Alternative
1. 2.
3.
4. 5.
/* /* /* /*
*/ temp */ x */ y */
if ( late_charge> 0.0) { printf("\nBill includes $ %.2f late charge", late_charge); printf(" on unpaid balance of $ %. 2f\n", unpaid);
}
1. 2. 3. 4. 5. 6. 7. 8. 9.
/*
* Computes use charge with conservation requirements * Pre: previous, current, and use_last_year are defined.
*/
double comp use_charge(int previous, int current, int use_last_year) { int used; /* gallons of water used (in thousands) double use_charge; /* charge for actual water use
*/ */
(colltillll ed )
13.
14. 15. 16.
17.
18. 19. 20. 21. 22. 23.
return (use_charge);
}
/*
2. 3. 4. 5. 6. 7. 8.
9. 10. 11.
double tax;
i f (salary < 0 . 0) tax = -1. 0 ;
12.
13.
(continu ed)
14. 15. 16. 17. 18. 19. 20. 21 . 22. 23. 24. 25. 26. 27. 28.
else if (sa l ary < 15000 . 00) tax = 0 . 15 * salary; else if (salary < 30000 . 00) tax = (salary - 15000 . 00) else if (salary < 50000.00) tax = (salary - 30000 . 00) else if (salary < 80000 . 00) tax = (salary 50000.00) else if (salary <= 150000.00) tax = (salary - 80000 . 00) else tax = -1. 0;
/* first range /* second range * 0.18 + 2250.00 ; /* third range * 0.22 + 5400.00; / * fourth range * 0.27 + 11000.00 ; /* fifth range * 0.33 + 21600.00;
*/ */ */ */ */
return (tax) ;
}
Figure 4.12 Example of a switch Statement with Type char Case Labels