Advertisement
AKIB37

Untitled

Feb 18th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. Exploit return of integer values
  2. (i >= j) + (i == j) → 0, 1, or 2 based on relation between
  3. i and j
  4.  
  5. Calculating a Broker’s Commission
  6. • When stocks are sold or purchased through a broker, the
  7. broker’s commission often depends upon the value of the
  8. stocks traded
  9. • Suppose that a broker charges the amounts shown in the
  10. following table:
  11.  
  12. Transaction Size Commission Rate
  13. Under $2,500 $30+1.7%
  14. $2,500-$6,250 $56 + 0.66%
  15. $6,250-$20,000 $76 + 0.34%
  16. $20,000-$50,000 $100 + 0.22%
  17. $50,000-$500,000 $155 + 0.11%
  18. Over $500,000 $255 + 0.09% 16/31
  19.  
  20. Programming Task
  21. Calculating a Broker’s Commission
  22. • The minimum charge is $39
  23. • Write a program that asks the user to enter the amount of the
  24. trade, then displays the amount of commission:
  25. Enter value of trade: 30000
  26. Commission: $166.00
  27. • Use cascaded if statements to determine which range the
  28. trade falls into
  29.  
  30.  
  31. The “Dangling else” problem
  32. • Solution:
  33.  
  34. if ( y != 0) {
  35. if ( x != 0)
  36. result = x / y;
  37. }
  38. else
  39. printf("Error: y is 0\n");
  40.  
  41. if(y != 0)
  42. if(x != 0)
  43. result = x / y
  44. else
  45. printf("Error: x is 0\n");
  46. else
  47. printf("Error: y is 0\n");
  48.  
  49.  
  50.  
  51.  
  52. Any number of statements are allowed 26/31
  53.  
  54. • If the default case is missing and controlling expression is
  55. false, control passes to next statement after switch 28/31
  56.  
  57.  
  58.  
  59. total_checked
  60.  
  61.  
  62. • Declared variable is not visible outside the loop
  63. for (int i = 0; i < n; i++)
  64. {
  65. printf("%d\n", i); // Legal; i is visible
  66. }
  67. printf("%d", i); /*** WRONG ***/
  68.  
  69.  
  70.  
  71. 17/27
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement