Topic: Introduction to Problem Solving and Program
Sub-topic: Introduction to output, input and processing
Objective: Students should be able to perform basic calculations in programming.
Table of Content
The problem ............................................................................................................ 3
Solution .................................................................................................................. 4
Open your compiler ................................................................................................. 5
Create your code ..................................................................................................... 6
Explanation ........................................................................................................... 10
Class Activity ......................................................................................................... 11
The problem
When we create code, it's normally to solve a problem
Here is the problem we are going to solve today.
“We need a calculator program to check the sum of two numbers”
Solution
1. We need the user to enter 1 number and let the computer store that number
2. Ask for another number, then store that number
3. Then add the two number and store the result in sum
4. Print sum on screen
Open your compiler
Reopen your compiler and delete everything.
Create your code
Step 1:Type your program name
Step 2: Declare your variables
Step 3: Start your program by typing begin
Step 4: Ask the user for the first number
Step 5: Store the number in num1
Step 6: repeat for num2
Step 7: Add the two numbers and store the result in sum
Step 8 : Print the value in sum
Step 9 : End the program
Step 10: Execute the code
Step 11: Type your first value then, press enter. I typed 18
Step 12: Type your next value in then press enter
Step 13: Look at the result
Explanation
Program Name: program SimpleAddition; - This names our program "SimpleAddition".
Variables Section: var num1, num2, sum: integer; - This creates three integer variables
to store our numbers and result.
Begin and End: These mark where our instructions start and finish, just like in the Hello
World program.
Input/Output:
• The writeln lines display messages to the user
• The readln lines wait for the user to type a number and press Enter
• Each instruction ends with a semicolon (;)
Calculation: sum := num1 + num2; - This adds the two numbers together and stores the
result in the variable called "sum".
Final Output: writeln('The sum is: ', sum); - This displays the result to the user.
Period: The program ends with a period (.) to mark its completion.
Class Activity
Create and run the program below that finds the average of three numbers
Steps.
Saving and uploading.
1. When you are finished, take a screenshot like the one above and save it as
“Averageofthree program”. Upload it to the Teams assignment.