• + 75 comments

    In short, this is due to order of operations (PEMDAS). The operation inside the parentheses is evaluated first, and then it is multiplied with dMealCost.

    nTipPercent is an int and 100 is an int, and enclosing them in parentheses means that their result will be calculated first. The result of int / int = int; because a % is a fraction < 1, the result evaluates to 0 in integer division (so you're basically multiplying dMealCost * 0). If you change 100 to 100.0, it will evaluate as a double.