你的代碼對一個參數進行賦值動作。
以一個臨時變量取代該參數的位置。
int discount(int inputVal, int quantity, int yearToDate) {
if(inputVal > 50) inputVal -= 2;
| |
\ /
int discount(int inputVal, int quantity, int yearToDate) {
int result = inputVal;
if(inputVal > 50) result -= 2;
以一個臨時變量取代該參數的位置。
int discount(int inputVal, int quantity, int yearToDate) {
if(inputVal > 50) inputVal -= 2;
| |
\ /
int discount(int inputVal, int quantity, int yearToDate) {
int result = inputVal;
if(inputVal > 50) result -= 2;