Chapter 8. Math and Finance

If I offered you $15,000 or one dollar that doubled every day for 30 days, which one would you choose? By the time we finish the chapter, you'll know if you've chosen wisely.

We'll use the Indian folktale by Demi, "One Grain of Rice," to inspire our project and to demonstrate the power of doubling. In the folktale, a village girl asks a greedy king to double a single grain of rice each day for thirty days as a way to accumulate enough rice to feed the hungry villagers.

In this chapter, we will illustrate the math behind the folktale and compare it to conventional interest-based accrual methods. Specifically, we will:

  • Calculate the total amount of money if we double a dollar each day
  • Collect user input via slider input controls
  • Graph the results of a calculation using the pen and stamp tools
  • Build interactive math problems using variables
  • Calculate simple interest on an amount of money

I'm using dollars as the basis for my project, but the math works whether we use euros, rice, or chicken legs.

Double it or lump sum?

Let's refine our problem statement to include an interest calculation: Would you rather earn 4% interest on $15,000 for one month or receive $1 that doubles every day for 15 days?

To help us make the right choice, we will do both calculations. We'll show the results of the doubled amount using a graph, and we'll use a sprite to report the interest amount.

We'll build some user-input features into each calculation so that the user can experiment with variable amounts.

We'll begin by setting up the equation to calculate the doubled amount and its graph.

Double it

The doubling formula is relatively simple. Day two's value is twice as much as day one's. Day three's is twice as much as day two's, and on and on it goes.

We can represent the math with this equation:

newAmount = startAmount x 2

Before you begin, create a new sprite in the shape of a circle. The ellipsis tool in the Paint Editor works well for this. We'll use this sprite to draw the points on our graph, so make it relatively small. Name the sprite double.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.152.254