C3.1 Solve problems and create computational representations of mathematical situations by writing and executing efficient code, including code that involves events influenced by a defined count and/or subprogram and other control structures.

Activity 1: Budget


Provide students with the chart below that states the cost of various clothing items. Next, share with the students that their task is to write code that will determine the total cost of the items based on the following order.

13 long sleeve shirts

15 sweaters

12 short sleeve shirts

30 jogging pants

10 rain coats

Short Sleeve Shirt Long Sleeve Shirt Sweater Jogging Pants Rain Coat
$10.99 $13.99 $15.99 $15.99 $23.99

For example, the student may write code such that the type of item, its corresponding cost, and corresponding quantity is entered on command and the "SUM" variable is updated after each entry.

Next, have students write a subprogram that will be executed if certain conditions are met. For example, apply a 30% discount if the total exceeds $100, or offer a free item if the order exceeds 10 items.

Example of code with subprogram to apply a discount

Activity 2: Measures of Central Tendency


Have students create subprograms that calculate the mean, median, mode, and range. These subprograms could then be executed at strategic locations in a main code that would analyze a data set.

This activity could be a continuation of Activity 1. For example, the student would create a subprogram that calculates the average unit cost of purchasing multiple items.