Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exploit return of integer values
- (i >= j) + (i == j) → 0, 1, or 2 based on relation between
- i and j
- Calculating a Broker’s Commission
- • When stocks are sold or purchased through a broker, the
- broker’s commission often depends upon the value of the
- stocks traded
- • Suppose that a broker charges the amounts shown in the
- following table:
- Transaction Size Commission Rate
- Under $2,500 $30+1.7%
- $2,500-$6,250 $56 + 0.66%
- $6,250-$20,000 $76 + 0.34%
- $20,000-$50,000 $100 + 0.22%
- $50,000-$500,000 $155 + 0.11%
- Over $500,000 $255 + 0.09% 16/31
- Programming Task
- Calculating a Broker’s Commission
- • The minimum charge is $39
- • Write a program that asks the user to enter the amount of the
- trade, then displays the amount of commission:
- Enter value of trade: 30000
- Commission: $166.00
- • Use cascaded if statements to determine which range the
- trade falls into
- The “Dangling else” problem
- • Solution:
- if ( y != 0) {
- if ( x != 0)
- result = x / y;
- }
- else
- printf("Error: y is 0\n");
- if(y != 0)
- if(x != 0)
- result = x / y
- else
- printf("Error: x is 0\n");
- else
- printf("Error: y is 0\n");
- Any number of statements are allowed 26/31
- • If the default case is missing and controlling expression is
- false, control passes to next statement after switch 28/31
- total_checked
- • Declared variable is not visible outside the loop
- for (int i = 0; i < n; i++)
- {
- printf("%d\n", i); // Legal; i is visible
- }
- printf("%d", i); /*** WRONG ***/
- 17/27
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement