CGS2423 Assignment 4
Due 3/28 at the start of class
Create a program that does the following.
Create and use a function named intro that explains what your program
does.
Create a function named menu that displays the following:
Calculating PI
(1) Specify the number of terms
(2) Specify the precision
(3) Exit
Make a menu selection:
Call the menu function and then read a value from the user. Validate
that the number is between 1 and 3. If it is not in this range, then
tell the user the input was incorrect, and read a new value. Continue this
process until a valid number is entered. You must also handle the case if
a character is entered instead of a number.
In options (1) and (2), the value of PI will be calculated using the formula
in question 2 on page 227 of the text.
-
For option (1)
-
The user will enter how many terms should be used in the calculation. Validate
that the number is between 1 and 20000000. If it is not in this range, then
tell the user the input was incorrect, and read a new value. Continue this
process until a valid number is entered. You must also handle the case if
a character is entered instead of a number.
-
Display the value of PI that was calculated and the value of the last term
that was used in the calculation.
-
By using the acos function, display acos(-1.0) to 12 places. This
will give you a reference for how close your calculation is to the real value
of PI.
-
For option (2)
-
The user will indicate how small the last term can be before stopping the
calculation. The use will enter the absolute value of the smallest term to
enter. Validate that the number is between 1.0E-8 and 1.0. If it is not in
this range, then tell the user the input was incorrect, and read a new value.
Continue this process until a valid number is entered. You must also handle
the case if a character is entered instead of a number.
-
Display the value of PI that was calculated and the number of terms that
were used in the calculation.
-
By using the acos function, display acos(-1.0) to 12 places. This
will give you a reference for how close your calculation is to the real value
of PI.
If option (3) is chosen, then display three totals: the number of times that
option (1) was called, the number of times that option (2) was called, and
the number of times that an incorrect menu option was entered.
Repeat the process of displaying the menu, reading an option from the user,
and performing the task for that option, until the user enters option 3.
Only display the introduction once.