Creating a Cash Register Program to Learn about Percents

By: Dawn DuPriest

Dawn DuPriest is a Computer Science teacher at Preston Middle School in Fort Collins, Colorado. She found her calling in teaching math and computers after nearly a decade of working as a software engineer. Dawn enjoys programming in many languages and playing Minecraft with her daughters. Find her on Twitter at @DuPriestMath or online at http://codinginmathclass.wordpress.com/

Did your school celebrate Computer Science Education Week (http://csedweek.org) in December? This event draws attention to computer science as a key literacy skill for students, and the popular “Hour of Code” tutorials and puzzles are a fantastic way to introduce young people to the problem-solving and language involved in working with computers.

As the computer science teacher in a STEM middle school, I coordinated our school’s efforts around CS Education Week and the Hour of Code. Many teachers in the building dedicated an hour allowing kids to solve computing puzzles on the website (http://code.org/learn). Many teachers approached me about making the activity relevant to their discipline – and one math teacher used CS Education Week to involve his students in a unit project on tax and discount using coding.

Ryan Martine’s class is a standards-based sixth-grade class. His students were close to the end of a unit of study on percents, using this item from the Common Core State Standards.

CCSS.MATH.CONTENT.6.RP.A.3.C

Find a percent of a quantity as a rate per 100 (e.g., 30% of a quantity means 30/100 times the quantity); solve problems involving finding the whole, given a part and the percent.

Ryan met with me ahead of time to ask about doing a coding project for his class. As the sixth-graders were learning about how to calculate prices including discounts and tax, one of the students asked: “Mr. Martine, is this what a cash register does?”

And he thought: why not have them design a cash register program?

I gave Ryan a lightning lesson on variables and math in Scratch, and he designed the lesson. As an introduction, he showed this program on the board.

dawn_1The cat asks you questions a cash register would care about: the name and price of two items, and the percent discount on a coupon. Don’t forget the city sales tax! And good news – today everything is on sale for an additional 20% off!

At the end, the cash register cat tells you the final price of your items. Kids volunteered different items for different prices: tarantulas for $500, light sabers for $1200, apples for $6.25. Each time, they chose a different discount and discussed the final price and what it meant.

Ryan gave the kids their project prompt: “For your Hour of Code, you’re going to make a project just like this!”

He allowed kids to self-select whether they were beginners, intermediate, or advanced. Each group could choose a starter program with different amounts of scaffolding – structure already built into it. The beginners could start with a project with most of the math formulas in it, but it needed the variables and numbers filled in. The advanced students started with just a few variables. Some students even chose to start completely from scratch and just use the skeleton programs as a reference if they got stuck.

dawn_2The beginner program, above, contains all of the variables and much of the structure, and is missing details.

dawn_3The advanced program starter, shown here, has the basic flow of the program but no math and many gaps.

Kids worked on their programs for several class periods. On the first day, they did the launch, inspected the skeleton program they chose, and got started. On the second day they created their programs and conferred with Ryan and each other, and day three was dedicated to troubleshooting and sharing with their peers.

One of my computer students was excited to show me her creation.  “Look, Ms. DuPriest! We’re making a shopping program in Scratch in math class. I’m really proud of mine.” She showed me a program with an adorable snow monster wearing an ugly sweater, asking about prices and discounts. We ran her program a few times and I asked her questions. “Does that price make sense?” she noticed some errors just by sharing the program with me, and fixed them on the spot.

Storytelling and creativity are important to the Scratch experience. The students learned about consumer math by doing the activity, and it was also meaningful to them to create a storyline with character and color.

After students finished their cash register projects, Ryan surveyed his class about their thoughts on learning percents by programming. He asked if this was a good way to learn about percents. Students who responded “Yes” said:

“This was a good way for me to learn about percents.”
“I felt like I was teaching someone else how to do it.”
“Coding is problem solving and it helps solve different math problems.”

Interestingly, students who said “No” said “This isn’t math, it’s just programming. I told the computer how to do the math, but I didn’t do it.” We found it fascinating that some students don’t believe it’s mathematics if they don’t do the calculations by hand. This perception lies at the heart of mathematics teaching reform. Hand-calculating is less emphasized as it involves following a rigid procedure and focusing on a single correct answer. Coding, a form of modeling, allows students to analyze a problem’s structure, create an abstract model, and then solve an infinite number of problems using their model – key ideas in the Common Core’s Standards for Mathematical Practice.

In addition, Ryan found his kids hit on algebraic ideas which will be introduced later in sixth grade.

CCSS.MATH.CONTENT.6.EE.B.6

Use variables to represent numbers and write expressions when solving a real-world or mathematical problem; understand that a variable can represent an unknown number, or, depending on the purpose at hand, any number in a specified set.

By creating a cash register in Scratch, students now have some background in what variables and expressions mean in a real world context. They also no longer take for granted what cash registers do.

And they had a great time working together and being creative.

To see Ryan’s programs for his lessons, refer to these links:

The starter program – demonstrated on the board, but code not shown:
https://scratch.mit.edu/projects/90258028/

Starter programs for different levels:

Beginner:  https://scratch.mit.edu/projects/90522811/

Intermediate: https://scratch.mit.edu/projects/90519508/

Advanced: https://scratch.mit.edu/projects/90521476/

Ryan Martine has been a math teacher and instructional coach at the middle school level for 16 years.  He strives to apply mathematics in many ways.  Recently, he has been working to learn about coding as one of math’s applications. He resides in Colorado. Follow him on twitter: @RyanMartine