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:
-
creating and using counters and accumulators.
-
a loop
-
user input from the keyboard
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:
-
the sum of the integers from 1 to the upper limit (including the upper limit)
-
the square root of the sum of all integers in the sequence
-
the sum of the floor of the square root of each integers in the sequence
(remember the floor is the integer part of a number with decimal places)
-
the product of all the integers in the sequence
-
the average of all the integers in the sequence
Each result you compute will be reported in an "alert" statement.
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:
-
sum of the integers: 1+2+3+4 produces 10
-
square root of the sum of the integers: Math.sqrt(10) produces 3.1622776601683795
-
sum of the floor of the square root of each integer:
Math.floor(Math.sqrt(1))+Math.floor(Math.sqrt(2))+
Math.floor(Math.sqrt(3))+Math.floor(Math.sqrt(4)) produces 1+1+1+2 is 5
-
product of the integers: 1*2*3*4 produces 24
-
average of the integers: (1+2+3+4) / 4 produces 10/4 which is 2.5