Overview

The rate at which something grows along with the amount of time the growth is allowed to continue has a significant impact on the final result. A classic demonstration of exponential growth outpacing linear growth can be observed in the output produced by the solution to this laboratory assignment.

Details

Write a program that produces output similar to the following examples:

You've been hiking all your life. One day, you come across a fork in the trail
that you're sure wasn't there before. Never one to stray from adventure, you
boldly take the left path. As you progress, the forest around you starts to
change: bark becomes smooth, leaves take on a purple hue, and the ground
itself squishes beneath your boots. As you take in your surroundings, an
ethereal voice seems to come from all directions at once.

"Greetings, traveler."

"We have been watching you for a long time... You are not like other humans;
you only have 9 toes. This pleases us greatly. As a token of our admiration,
we will grant you wealth beyond your wildest dreams! So long as you live, we
will give you the first share of every harvest: the finest rutabagas; far
greater than any your kind has ever known!"

"We will grant this boon one of two ways: you may either opt to receive
372 bushels of rutabagas each year, or you may choose to receive a single
bushel this year, but we will double the amount with each harvest.
Choose wisely!"

Enter "1" if you would prefer to receive 372 bushels each year,
or enter "2" if you would rather risk exponential growth: 1

Total rutabagas received after N harvests
=========================================
Harvest 1    Linear: 372,    Exponential: 1
Harvest 2    Linear: 744,    Exponential: 3
Harvest 3    Linear: 1116,    Exponential: 7
Harvest 4    Linear: 1488,    Exponential: 15
Harvest 5    Linear: 1860,    Exponential: 31
Harvest 6    Linear: 2232,    Exponential: 63
Harvest 7    Linear: 2604,    Exponential: 127
Harvest 8    Linear: 2976,    Exponential: 255
Harvest 9    Linear: 3348,    Exponential: 511
Harvest 10    Linear: 3720,    Exponential: 1023
Harvest 11    Linear: 4092,    Exponential: 2047

You live to see 11 harvest(s) so you got lucky and
will end up with an extra 2045 bushels of rutabagas!

Do you want to play again? (Y/N)
N

Each row displays the total number of rutabagas received after N number of harvests. For example, for harvest 3, linear is 1116 (372 three times), and expontential is 7 (1 bushel the first harvest, 2 bushels the second harvest, and 4 bushels the third harvest for a total of 7 bushels).

Here the number of rutabagas received each year using option one should be a value between 200 and 2000 that is randomly generated, and the number of harvests the user lives to see should be randomly generated and no more than 93.

Also, if the user enters Y to the last question, the entire program should run again.

Another example output is shown below:

...

Enter "1" if you would prefer to receive 508 bushels each year,
or enter "2" if you would rather risk exponential growth: 2

Total rutabagas received after N harvests
=========================================
Harvest 1    Linear: 508,    Exponential: 1
Harvest 2    Linear: 1016,    Exponential: 3
Harvest 3    Linear: 1524,    Exponential: 7
Harvest 4    Linear: 2032,    Exponential: 15
Harvest 5    Linear: 2540,    Exponential: 31
Harvest 6    Linear: 3048,    Exponential: 63
Harvest 7    Linear: 3556,    Exponential: 127
Harvest 8    Linear: 4064,    Exponential: 255
Harvest 9    Linear: 4572,    Exponential: 511
Harvest 10    Linear: 5080,    Exponential: 1023
Harvest 11    Linear: 5588,    Exponential: 2047
Harvest 13    Linear: 6096,    Exponential: 4095
Harvest 14    Linear: 6604,    Exponential: 8191

You live to see 20 harvest(s). Your poor choice cost
you 1038415 bushels of rutabagas!

Do you want to play again? (Y/N)
N

Notice that here the user saw 20 harvests, but only 14 of them are shown in the output. That is because once the Exponential option exceeds the linear option, your program should no longer show the total bushels of rutabagas accumulated for each option; however, your program still needs to calculate the accumulations so that it can determine how many more bushels of rutabagas more the exponential option had than the linear option.

Once you have your program working as described above, you should use your creativity to modify the scenario to something different (no 9-toed humans, no rutabagas, etc...). Your program must still produce the same linear and exponential values but associate a different meaning with them. Your output should look something like what follows where the xs are replaced with your ideas.

xxxxxx xxxx xxxxxx xxx xxxx xxxx. 

Enter "1" if you would prefer to receive 1000 bushels each year,
or enter "2" if you would rather risk exponential growth: 1

Total xxxxxxxxx received after N xxxxxxxx
=========================================
Xxxxxxx 1    Linear: 1000,    Exponential: 1
Xxxxxxx 2    Linear: 2000,    Exponential: 3
Xxxxxxx 3    Linear: 3000,    Exponential: 7
Xxxxxxx 4    Linear: 4000,    Exponential: 15
Xxxxxxx 5    Linear: 5000,    Exponential: 31
Xxxxxxx 6    Linear: 6000,    Exponential: 63
Xxxxxxx 7    Linear: 7000,    Exponential: 127
Xxxxxxx 8    Linear: 8000,    Exponential: 255
Xxxxxxx 9    Linear: 9000,    Exponential: 511
Xxxxxxx 10    Linear: 10000,    Exponential: 1023
Xxxxxxx 11    Linear: 11000,    Exponential: 2047
Xxxxxxx 13    Linear: 12000,    Exponential: 4095
Xxxxxxx 14    Linear: 13000,    Exponential: 8191
Xxxxxxx 15    Linear: 14000,    Exponential: 16383

You live to see 15 xxxxxxx(s). Your poor choice cost
you 2383 xxxxxxxx!

Do you want to play again? (Y/N)
N

Notes

Just For Fun

Ambitious students may want to:

Xxxxxxx  9    Linear:  9000,    Exponential:  511
Xxxxxxx 10    Linear: 10000,    Exponential: 1023

If you have ideas to improve the program that don't comply completely with the specified requirements, consult with your instructor first.

Acknowledgement

This laboratory assignment was developed by Dr. Derek Riley and the CSC1110 instructors.

See your professor's instructions for details on submission guidelines and due dates.