From the course: C Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Get the order correct

Solution: Get the order correct - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Solution: Get the order correct

(upbeat music) - I hope you appreciated the descriptive variable names in the Challenge Exercise File. Programmers who write good code, use names such as these. No confusion. Starting at line seven, I assign 12 to the variable rooms, 16 to variable paintings, and four to variable sculptures. The proper equation is listed at line 11. The calculation inside the parentheses happens first. The value of paintings is added to the value of sculptures. Once this value is obtained, the equation works left to right. With the number of rooms multiplied by the result of the operation in parentheses. If you omit the parentheses, rooms is multiplied by paintings first. And then that whole result is added to sculptures. This outputs an incorrect result, 196. Only when you use parentheses to override the order of precedence, will you arrive at the proper result and keep your cushy programming job at the museum.

Contents