Assignment 1: Counters and Accumulators

Overall program description

Ok, so you are not going to become a facebook/google style billionaire selling this program to some rich investors, but for your first program it will give you some exercise with the basics... which of course, is a very good place to start.

In this program you will practice several of the concepts we have studied:

The first step in your program will be to get a number from the user. You will use a "prompt" statement to do this (remember to do the "safe" prompt which converts the text to a number). Ask the user for an integer to be an upper limit (see "Points for Thought" below). Your program will then produce several computations from the sequence of integers from 1 to whatever upper limit the user has given.

You will compute these values:

Each result you compute will be reported in an "alert" statement.

Examples

Let's say the user gives us the integer 4 as upper limit. The program will then work with the integer sequence 1, 2, 3, 4. The program will compute these values:

Hints

You can use a "for" loop to generate the integers in the sequence, one at a time. The loop index will give you the current integers in the sequence. Remember, the loop index counts how many times the loops body has been executed.

Use a accumulator inside the loop body to build up the sum of all the integers. Use another accumulator in the body similarly to build up the product. Use yet another accumulator in the body to build up the sum of the floor of the square root; this building will require calling the Math functions "floor" and "sqrt" correctly.

You can use a counter in the loop body to count how many integers are in the sequence (since you will have to divide the sum by the number of integers to get the average). However, you can also recognize that since we start the sequence at 1, the upper limit tells directly how many integers are in the sequence.

Points for Thought

How might you check to be sure the number the user gives as upper limit is actually an integer (as opposed to something like 13.75)?