PERFORMING MATHEMATICAL CALCULATIONS ON TURBO PASCAL
In the previous lesson, we understood how to declare variables so that users can input their choice when being surveyed. What happens if users want a program to make their lives easier by helping them do math? In order for your platform to understand more of what you want it to do, we must first analyze two other variables. Real numbers and Integers.
Integers: whole numbers without decimal places
Real numbers: numbers with decimal places
Real numbers: numbers with decimal places
Have a look at the following program script on how to calculate the circumference and area of a circle based on user input of the circle's radius:
Step 1: Declare your variables by stating the variable type. Step 2: Announce to your users what this program does. New function: the difference between 'writeln' and 'write':
Programmers need to use the 'write' function if they want the program to read the user input afterwards. Hence, you will see on the same line a following 'readln' command that states what needs to be read by the program in brackets.
**Also, what goes in between the brackets must be a declared variable at the top before the program begins.**
Step 3: Create a table with headings for the calculated results to be displayed under. Notice how there is a colon in the second part of the command. The number next to the colon controls the amount of spaces indented before the words are placed.
In the shown example the last letter of the word "Radius" is 10 spaces from the left side of the screen, Circumference (a longer word) requires more spacing so the "e" is 15 spaces to the right of the "s" in Radius, and Area is 10 spaces after.
Step 4: Create commands that incorporate the equation on how to calculate the circumference and area of a circle based on the user input's of how big the radius is.
NOTE: Notice how the field of input for your users to specify the radius is set by your program (by declaring that particular variable) to be an integer. This helps simplify and limit the calculations that are possible by keeping radius length in whole numbers. |
HOWEVER: the answers displayed by your entered formula are shown as real numbers so we can be as precise as we want it to be. In this case, the program is displaying its calculated answers to a precision point of 2 decimal places. This is why there is an additional colon and #2 after the space is declared.
|
Assignment #3:
Suppose a shotgun shell company wants to hire you to create a program that can calculate the surface area of three different sizes of shotgun shells for the factory to manufacture. Create a program that lets your contractor play around with different inputs and will ultimately display the surface area calculations in an organized table for him or her to see to an accuracy of 2 decimal places.
Out of 13 marks. See Skills Mastery List on the right. |
Skills Mastery List:
|