39
Calculator apps Program math formulas with Small Basic. a challenge for classrooms around the world.

Small Basic Calculator Apps lesson

Embed Size (px)

Citation preview

Page 1: Small Basic Calculator Apps lesson

Calculator appsProgram math formulas with

Small Basic.

a challenge for classrooms around the world.

Page 2: Small Basic Calculator Apps lesson

“The 'Hour of Code™' is a nationwide initiative by Computer Science Education Week and Code.org to introduce millions of students to one hour of computer science and computer programming.”

Hour of Code™

www.smallbasic.com www.code.orgashiedujude.blogspot.com

#sbcalculatorapps#smallbasic#hourofcode#globalgoals

www.csedweek.org

Page 3: Small Basic Calculator Apps lesson

About Calculator Apps projectThis is a customized snack course for teachers and students of elementary

and secondary schools worldwide, as part of the sustainable development project for quality education via global goals; for those who are new to computer programming and would love to have a starter pack to inspire them. Also, teachers who find it difficult to introduce computer programming in their classrooms, especially to ages 8 and 15 students will find it helpful to use, as a Kickstarter into explaining the rudiments of coding to these categories of young children.Small Basic is the sample programming language throughout this course due to it’s simplicity. It would be very difficult to introduce majority of young students into computer programming no matter how easy it is, without first creating a background check on Algorithms and how our day to day living depends on them. At interval you will meet my sidekick on Small Basic, his name is Wazobi, a stick figure that will take you through the course via animated videos.

Page 4: Small Basic Calculator Apps lesson

Download link for Small Basic: www.smallbasic.com

Download .NET 4.6 to install Small Basic:https://www.microsoft.com/en-us/download/details.aspx?id=53344

Details about Calculator Apps project at:ashiedujude.blogspot.com

Discussion forums on Facebook and Twitter:

@edujetage

Page 5: Small Basic Calculator Apps lesson

Installation tips for Teachers:1. First download and Install .NET ver 4.6 and above setup file. 2. Before downloading and installing Small Basic setup file.

If you have multiple computer systems to install both setup files:3. Copy both files from the download folder into a new folder.4. Rename the new folder and copy it into an external storage (Flash drive etc)5. Switch on all computer you would need to install both setup files.6. Copy and paste the setup folder containing files on each PC.7. Then begin installation.

Page 6: Small Basic Calculator Apps lesson

Name of Lesson: Algorithms Subject: ICT Instructor: Ashiedu JudeGrade:

Students that can solve basic math of addition, subtraction, multiplication, division.

Subject of Lesson: 1. Definition and uses of Algorithms in day to day activities.2. Logical Algorithm 3. Algorithms in relation to mathematics. 4. Algorithms in relation math exercises.

Pupils/students assignment:* List short details of your activities in the last one hour.* List short details of your activities in the last 24 hours * Write an algorithm to add up five numbers. * Write an algorithm to add up two numbers and divide them by a single number.*

Lesson outline/Objective: • Learners can create simple algorithms from math formulas.• Learners can automate an algorithm with conditional events.

Teacher’s notes:* *

References(Books/web etc.):**

Resources:* Photos and video about algorithm. • A foot ball• Food menu and recipe on cards• Short essay in English language and a Foreign

language .

Minutes: 30-45

Overview/Purpose: To enable learners understand Algorithms and how we create them on daily basis.

Page 7: Small Basic Calculator Apps lesson

AlgorithmHumans work with algorithms everyday unconsciously. This is how we live and this is also how things get done from your to-do list to your shopping lists. The algorithm of an average student’s life is as simple as:

This can be expanded into details by breaking down each step further into mini algorithms like a table of contents.

An Algorithm is simply a list of processes to complete a specific task or event.Algorithms help us understand how to write codes for the computer.

Step 1: HomeStep 2: SchoolStep 3: Home

Step 1: HomeStep 1.1 Brush(Teeth)Step 1.2 Bath

Step 2: SchoolStep 3: Home

Page 8: Small Basic Calculator Apps lesson

Logical AlgorithmsWe have several logical or conditional ways of creating algorithms by using IF, GOTO and ENDIF and ELSIF commands. These are also Small Basic commands. Lets change your normal student routine, to a situation that happens when you fall sick on a school day.

You find that our normal TASKS will change when there is a new EVENT. Step 1: HomeStep 2: IF sickStep 3: GOTO hospitalStep 4: ELSEIF treatedStep 5: GOTO SchoolStep 6: ENDIF Home

Step 1: HomeStep 2: SchoolStep 3: Home

Page 9: Small Basic Calculator Apps lesson

Algorithm example 1

An Algorithm is like a cookbook you can not eat the menu on paper after shopping for items. The foodstuffs has to cooked according to the process in the menu.If your tummy was a computer, it wouldn’t know how to digest raw foods; the cookbook is the algorithm, the chef is the programmer, while cooking the foodstuffs is the programming language. When you eat raw food you can become sick or get nauseated, because your tummy might be rejecting the raw form of the food. A computer programming language will reject an algorithm, if it doesn’t understand the form the algorithm was typed.

Page 10: Small Basic Calculator Apps lesson

Algorithm example 2

You understand only English Language and you are given an essay to read in Chinese; you will need to ask someone that understands Chinese and English languages to translate it for you. The person who translates would write an short note (algorithm) on the meaning of each Chinese word or sentences in English, before typing as the essay for you. Humans can only teach computers in special languages called programming languages or codes. Algorithms helps us understand how computers work and they are the best way to explain our commands to computers. Algorithms are written step-by-step and computer programming languages obey commands (codes) one step at a time.

Page 11: Small Basic Calculator Apps lesson

Algorithm and Math

The basic mathematical symbols/operators :1. Addition (on keyboard “+”)2. Subtraction (on keyboard “-”)3. Division (on keyboard “/”4. Multiplication (on keyboard “*”)In computer programming, humans are the teachers, while computers are the learners.Computers are blind, deaf, dumb, and they are still growing; your job as a programmer is to teach computers to see, hear, talk and solve problems faster, so you have more time to play.When writing an Algorithm for a computer code, you are going to use a mouse and keyboard, your algorithm will have similarities with keys on the keyboard. By teaching a computer to solve a problem, it will never forget it. This will give you time to focus on teaching the computer more algorithms.

Page 12: Small Basic Calculator Apps lesson

Algorithm and math exercises.

If you had a job that pays you $1000 monthly to add two numbers each minute everyday. Would it not be smart to let your computer do the math?

This is a simple exercise in numeracy (2 + 3 = 5).We can use images to represent the numbers Now solve this: 1,000,000,000,000,000,000,000,000,000 + 2,000,000,000 = ?

Both exercises are still the addition of two numbers but the second exercise will take you more time to figure out and pronounce. But it will take a computer the same time (less than 0.1 sec) to calculate both math exercises with an algorithm that can be changed into a Small Basic code.

Page 13: Small Basic Calculator Apps lesson

Algorithm and math exercises contd.

Algorithm solution: (2 + 3 = 5). The plus and equal (+, =) signs are the only stable (constants) items in the math exercise, the rest are unstable “2,3,5” (variables/changing).We need to create a formula to keep adding two numbers, and formulas are created using the ALPHABET, but NUMBERS are used to test if the formulas can calculate.

With this algorithm we can use any computer programming language to write a code to add up two numbers, even if the numbers are in trillions.

the formula now has to come before the answer, so we swop the Steps 3 to Step 4, to make the algorithm calculate properly.

Step 1: The first number is 2, we can call it alphabet AStep 2: The second number is 3, we can call it XStep 3: The third number is the answer 5, we can call it ZStep 4: The formula looks like this (A+X=Z)

Step 3: A+X = Z Step 4: Z = 16

Step 1: First alphabet A = 11Step 2: Second alphabet X = 5

Page 14: Small Basic Calculator Apps lesson

Algorithm and math exercises contd.

By changing the mathematical sign we can write an algorithm to subtract or multiply or divide any two numbers; which looks like this:

With just one algorithm we have four more algorithms that can be made into simple calculator apps, using Small Basic programming language. An algorithm also helps us control how an app should work. Robots, the internet, software, apps all work with specific algorithms. We will learn how to convert our algorithms into Small Basic codes for the computer to learn how to make use of it.

Step 1: The first number is 2, we can call it alphabet AStep 2: The second number is 3, we can call it XStep 3: The third number is the answer 5, we can call it ZStep 4: The formula looks like this (A+X=Z) or (A-X=Z) or (A/X=Z) or (A*X=Z)

Page 15: Small Basic Calculator Apps lesson

Algorithm for shapes

The algorithm for finding the area of a square:

The algorithm for finding the Perimeter of a square:

Remember all sides of a square are equal, so you do not need to have different length, width or height.For other shapes like the rectangle we will need to add more steps to our algorithm to get numbers for width or base height.

Step 1: Length of one side is GStep 2: Area = G*G

Step 1: Length of one side is KStep 2: Perimeter = 4K

Page 16: Small Basic Calculator Apps lesson

Congratulations you completed your

lesson on Algorithms.

Page 17: Small Basic Calculator Apps lesson

Name of Lesson : Small Basic Calculator appsSubject: ICT Instructor: Ashiedu JudeGrade:

Students that can solve basic maths of addition, subtraction, multiplication, division.

Subject of Lesson: 1. General introduction to 3 STATEMENTS, PROPERTIES and OPERATIONS relevant for the lesson in Small Basic 2. Three major Small Basic STATEMENTS, PROPERTIES and OPERATIONS to solve most Math Problems3. Automating Small Basic calculator apps with Conditional, Loop Statements. 4. Debugging simple codes

Students assignment:* Create a Small Basic app to multiply 5 numbers.* Create a Small Basic app to calculate with this formula (K+y)5* Create a Small Basic app to calculate with this formula (a+b)(m+n)

* Create a Small Basic app to calculate the area of a Triangle* Debug the Codes at the end of the slide lesson.

Lesson outline/Objective: • Learners can use 3 major Small Basic commands solving

simple math problems with the idea of Soccer rules. • Learners can create simple Calculator apps using Small Basic

with the idea gained from writing Algorithms. • Learners can automate their Calculator app with conditional statements (If, Goto, Endif, Elseif etc)

Teacher’s notes:* Teachers can create more exercises for their students based on current level in numeracy.

References(Books/web etc.):* Small Basic PowerPoint tutorials at smallbasic.com*

Resources:* Relevant football match photos, videos, sound files. * A physical Football* A computer with Small Basic installed* Printed list of Math formulas for shapes.

Minutes: 70

Overview/Purpose: To enable learners understand Small Basic STATEMENTS, PROPERTIES & OPERATIONS for solving simple Math problems or what we can call Mini calculators, with previous idea

Page 18: Small Basic Calculator Apps lesson

Soccer commands and Small Basic Programming

Lets compare playing soccer (football) to Small Basic programming:Soccer as a sport is made of some rules which makes us call it a game. Other sports like hockey, basketball, polo, NFL all have their special rules that makes playing their games special. You can not apply soccer rules to hockey, neither can you apply basketball rules to NFL.Computer programming languages are software with special commands for creating apps. They are like different sports with their special rules. Small Basic has it’s own unique commands that helps you create apps.

Page 19: Small Basic Calculator Apps lesson

SOCCER COMMANDS/RULES One big soccer rule is kicking the ball; we can call it the KickBall command (STATEMENT, VERB(action word), Rule), which is done with the LEGS only, we do not kick the ball with our hands. It is wrong or an error to do that. We must KickBall to Pass, Dribble or take a Shot. We can make up a Soccer Command Plan: Lets put these soccer commands into groups i.e 1. KickBall (STATEMENT group);2. Pass, Dribble, Shot (PROPERTY group). Statement and property are separated by a DOT;3. Actions you put inside the bracket (OPERATIONS group)

KickBall

Pass

DribbleShot

KickBall.Pass (a team mate to read your action)

KickBall.Dribble (trick opponent with the ball)

KickBall.Shot (towards a distant position)

Automatic ball actions includes (this will lead us to conditional commands:1. Ball Bounces. 2. Ball spinning on the

floor.3. Ball going out of the

field.

Page 20: Small Basic Calculator Apps lesson

Small Basic Calculator app EDITOR and SOURCE CODE

All rules in soccer work only in the FIELD; similarly in Small Basic, we have an EDITOR that allows us to type in all commands that Small Basic must obey, in order to create our Calculator apps, we call these step-by-step commands SOURCE CODES. The Small Basic EDITOR looks like the photo below:

F5 or RUN tells Small Basic to create an app from all commands (SOURCE CODES) we typed in the Editor

LINES numbers gives us the number of code line typed, when we press the F5 key or RUN button.

Source Code Editor for typing codes

Page 21: Small Basic Calculator Apps lesson

1. TextWindow.WriteLine() - Moves & displays text on a new line in app screen.

2. TextWindow.Write() - Leaves & displays text on same line in app screen.

3. TextWindow.Read() - Allows letters to be typed in app screen.

4. TextWindow.ReadNumber() - Allows numbers to be typed in app screen.

5. Math.Power(number, powernumber) - i.e. 73 is Math.Power(7,3)

6. Math.Pi or Math.Cos() or Math.Tan() or Math.Sin() i.e. Math.Cos(30)7. Math.SquareRoot() - To get the square root of a

number. 8. GOTO, THEN - Command for branching one

code to another. 9. IF, ELSEIF, ENDIF. - To create a branch of events

when coding.

10. Inverted comma ‘ - Allows you comment on a line of code

11. Quote marks “” - Works with .Write() or .WriteLine to display text

in quote marks on app screen. ie.12. Variables - Numbers or letters you

create that are not in Small Basic; commands i.e. total

= sum1 + sum2

Summary of important Small Basic commands for the Calculator Apps lesson

Page 22: Small Basic Calculator Apps lesson

Small Basic Calculator app (Statements, Properties, Operations)

Small Basic app screen command is TextWindow. Like the KickBall STATEMENT works with other commands like (PASS, DRIBBLE or SHOT) separated by a DOT in our Soccer Command Plan.All calculators have a small screen that displays RESULTS. The TextWindow STATEMENT command tells Small Basic to display a small black app screen after the next command, when we press the F5 button on the keyboard or click RUN on the monitor. The small black screen shows that our calculator apps can display any result we are going to program on the SOURCE CODE editor.

Small black app screen appears after pressing F5/RUN button

Source Code

Page 23: Small Basic Calculator Apps lesson

TextWindow Properties and Operations Our entire lesson is focused on making Calculator apps, using 5 Small Basic commands. Small basic understands when you use the commands in the combination given below:i.e. TextWindow.Write (“Calculator Apps”)Displays the comment in the quote on the small black app screen after pressing F5/RUN. Using WriteLine instead of Write put your cursor on the next line in the small black app screen. TextWindow.ReadNumber() Displays a cursor for you to type in numbers only on the small black app screen after pressing F5 Take note of the DOT in-between the STATEMENT and PROPERTIES

TextWindow

Write

WriteLine

ReadReadNumb

erClear

STATEMENT

PROPERTIES

Page 24: Small Basic Calculator Apps lesson

IntelliSense & Comments

1. IntelliSense in Small basic provides suggestions on commands you try using on your EDITOR via a small box. It also provide you with the proper spelling and usage of a command you are not too sure of.2. Comments help you keep a note on each line of command you typed. As a young computer programmer, it is easy to forget the use of a code your typed on the Editor; a comment uses an “Inverted comma”, which tells Small Basic to ignore any command after the inverted comma. i.e ‘this is to test comments.

commentCode Only code in QUOTE was displayed

Page 25: Small Basic Calculator Apps lesson

Small Basic Math Symbols & Commands

1. Division: /2. Multiplication: *3. Addition: +4. Subtraction: -5. Square root: Math.SquareRoot(number)6. Power: Math.Power(number, x)7. Equal: =8. Greater than: > 9. Less than: <

Page 26: Small Basic Calculator Apps lesson

Small basic math example 1

O u r fi r s t a l g o r i t h m e x e r c i s e w a s t o c r e a t e a m a t h f o r m u l a t o a d d u p t w o n u m b e r s . We c a n n o w w r i t e S m a l l B a s i c c o d e s f o r o u r a l g o r i t h m i n t o :

T h e S m a l l B a s i c c o d e s s e e m t o b e d o u b l e d f o r e a c h l i n e o f a l g o r i t h m , b e c a u s e w e n e e d e d t o c h a n g e i t f r o m h u m a n l a n g u a g e t o a c o m p u t e r l a n g u a g e .

A n d a l s o h e l p u s r e a d w h a t t h e a p p w a n t s w h e n w e p r e s s F 5 o r R U N b u t t o n .

TextWindow.Write("Type the first number we call A:")firstnumber = TextWindow.ReadNumber()TextWindow.Write("Type the second number we call X:")secondnumber = TextWindow.ReadNumber()addingnumbers = firstnumber + secondnumberTextWindow.Writeline(addingnumbers)

Step 1: The first number is 2, we can call it alphabet A

Step 4: The formula looks like this (A+X=Z)

Step 2: The second number is 3, we can call it XStep 3: The third number is the answer 5, we can call it Z

App screens

Source code editor

Page 27: Small Basic Calculator Apps lesson

Small basic math Comments example 1

O u r a p p i s u p a n d r u n n i n g a s s o o n a s w e p r e s s t h e F 5 ke y o n t h e ke y b o a r d o r R U N b u t t o n o n s c r e e n .

A d d i n g c o m m e n t s a t t h e b e g i n n i n g a n d i n - b e t w e e n t h e p r o g r a m m a ke s i t e a s y t o r e a d a n d e x p l a i n t o y o u r t e a c h e r w h e n y o u r r u n t h e a p p u s i n g F 5 ke y.

C o m m e n t s y o u w a n t d i s p l ay e d i n t h e a p p s c r e e n a r e a l w ay s i n Q U O T E m a r k s ( “ c o m m e n t s ” ) .

W h i l e C o m m e n t s t o e x p l a i n w h a t e a c h c o d e l i n e d o e s a r e p l a c e d a f t e r a n i n v e r t e d c o m m a ( ‘ ) . A n d t h e y d o n o t a p p e a r i n t h e a p p s c r e e n a f t e r p r e s s i n g F 5 o r R U N .

TextWindow.WriteLine("THIS APP ADDS ANY TWO NUMBERS") 'to display text in quote marks

TextWindow.Write("Type the first number we call A:") ‘to display text in quote marksfirstnumber = TextWindow.ReadNumber() ' app ask for 1st numberTextWindow.Write("Type the second number we call X:") 'to display text in quote markssecondnumber = TextWindow.ReadNumber() 'app ask for 2nd numberaddingnumbers = firstnumber + secondnumber 'app calculates by adding numbers

TextWindow.Write("ADDING THE TWO NUMBERS GIVES:") 'to display text in quote marksTextWindow.Writeline(addingnumbers) 'app display answer

App screen

Source code editor

Page 28: Small Basic Calculator Apps lesson

Coding branches Making a branch code is like turning your program into a cross road; or when

you try adding a menu options into your app. You will notice such events on a phone call voice menu i.e. For English press 1

For Spanish press 2

GOTO, THEN, IF, ELSEIF & ENDIF are branch commands in Small Basic. IF English THENGOTO 1ELSEIF Spanish THENGOTO 2ELSEIF Yoruba THENGOTO 3ELSEIF Hausa THENGOTO 4ENDIF

Press 1 for English. Press 2 for

Hindi. Press 3 for Yoruba. Press 4 for

Chinese.

123

4

For each branch you will have to create other events when coding. These events represents each branch, which are options your app gives the user.

Page 29: Small Basic Calculator Apps lesson

Small Basic Branch or Conditional commands

C re a t i n g b r a n c h c o m m a n d s i n o u r a l g o r i t h m a p p w i l l m a ke t h e m a t h a p p a u t o m a t i c w i t h I F , G O T O , T H E N a n d E N D I F.

Start:TextWindow.WriteLine("THIS APP ADDS ANY TWO NUMBERS") 'to display text in quote marks

TextWindow.Write("Type the first number we call A:") ‘to display text in quote marksfirstnumber = TextWindow.ReadNumber() ' app ask for 1st numberTextWindow.Write("Type the second number we call X:") 'to display text in quote markssecondnumber = TextWindow.ReadNumber() 'app ask for 2nd numberaddingnumbers = firstnumber + secondnumber 'app calculates by adding numbers

TextWindow.Write("ADDING THE TWO NUMBERS GIVES:") 'to display text in quote marksTextWindow.Writeline(addingnumbers) 'app display answer

TextWindow.WriteLine("Type 1 to Continue Calculation") ‘to display text in quote marksTextWindow.WriteLine("Type ENTER key to Stop Calculation") ‘to display text in quote marksstart = 1 ‘to repeat addition when 1 is pressedIf TextWindow.ReadNumber() = 1 then ‘app waits for you to type 1 Goto start ‘app restarts addition pressing 1 EndIf ‘logic command to END the IF command

Step 1: The first number is 2, we can call it alphabet A

Step 4: The formula looks like this (A+X=Z)

Step 2: The second number is 3, we can call it X

Step 3: The third number is the answer 5, we can call it Z

Step 5: Ask to start by pressing “1” or ENTER key

Step 7: GOTO Step 1

Step 8: ENDIF app when ENTER key is pressed

Step 6: IF “1” is pressed THEN

Source code editor

Page 30: Small Basic Calculator Apps lesson

Small Basic Branch or Conditional Statements

The app we c reated in the prev ious s l i de wou ld c lose a f te r add ing any two numbers .

I f your j ob was to add severa l o the r numbers th roughout the day ; i t wou ld be s low, i f you have to press F5 or RUN but ton each t ime you need to repeat the add i t ion process .

You can make your math app keep runn ing t i l l you want i t t o s top ca l cu la t ing by add ing a branch command to your a lgor i thm and source code l i ke I F , ENDIF, GOTO, ELSE IF , and THEN commands .

Start:TextWindow.WriteLine("THIS APP ADDS ANY TWO NUMBERS") 'to display text in quote marks

TextWindow.Write("Type the first number we call A:") ‘to display text in quote marksfirstnumber = TextWindow.ReadNumber() ' app ask for 1st numberTextWindow.Write("Type the second number we call X:") 'to display text in quote markssecondnumber = TextWindow.ReadNumber() 'app ask for 2nd numberaddingnumbers = firstnumber + secondnumber 'app calculates by adding numbers

TextWindow.Write("ADDING THE TWO NUMBERS GIVES:") 'to display text in quote marksTextWindow.Writeline(addingnumbers) 'app display answer

TextWindow.WriteLine("Type 1 to Continue Calculation") ‘to display text in quote marksTextWindow.WriteLine("Type ENTER key to Stop Calculation") ‘to display text in quote marksstart = 1 ‘to repeat addition when 1 is pressedIf TextWindow.ReadNumber() = 1 then ‘app waits for you to type 1 Goto start ‘app restarts addition pressing 1 EndIf ‘logic command to END the IF command

App screen

Source code editor

Page 31: Small Basic Calculator Apps lesson

Small basic Math Objects

Math ob jec ts g ives us the opt ion to c reate more fo rmu las fo r our ca l cu la tor apps .

We are us ing the fo rmu la to find the numbers that a re ra i sed to any Power. i . e , ,

R e m e m b e r t o a l w ay s u s e t h e Te x t W i n d o w. Wr i t e ( ) t o d i s p l ay M a t h . P o w e r ( n u m b e r, p o w e r ) o n A P P s c r e e n

TextWindow.Write("Type a number to know the square:") ‘displays textsquare = TextWindow.ReadNumber() ‘app ask for numberTextWindow.Write("The square of the number:") ‘displays text in quoteTextWindow.Writeline(Math.Power(square,2)) ‘displays the power of 2

• Cos• Tan• Sin• SquareRoot• Power• Pi

Math.

App screens

Source code editor

Page 32: Small Basic Calculator Apps lesson

You can start by creating Small Basic calculator apps from these math formulas.

Page 33: Small Basic Calculator Apps lesson

Small basic codes example 3

O u r fi n a l ex a m p l e w i l l b e o n o u r a l g o r i t h m t o fi n d t h e A R E A a n d P E R I M E T E R o f a S q u a re .

TextWindow.WriteLine("App to calculate AREA & PERIMETER of a square")

TextWindow.Write("Type the value for any side:") ‘app displays textsgsides = TextWindow.ReadNumber() ‘app wants length typed

TextWindow.Write("The AREA of the square is:") ‘app display textTextWindow.WriteLine(Math.Power(gsides,2)) ‘app calculates & display area

TextWindow.Write("The PERIMETER of the SQUARE is:") ‘app displays textTextWindow.Writeline(gsides*4) ‘app calculates & display perimeter

Step 1: Length of one side is GStep 2: Area =

Step 1: Length of one side is GStep 2: Perimeter = 4 *G

App screens

Source code editor

Page 34: Small Basic Calculator Apps lesson

Debugging Debugging your code is correcting

errors (bugs) you made in the source code editor during typing or working with Small Basic codes.Making errors or mistakes in your source code stops your code from becoming a app when your press F5 or RUN button.Small Basic EDITOR will show you the LINE number(s) where error(s) where found, with an error message on each line. You can also debug a code by reading the COMMENTS section to know what it was meant to do; then you can rewrite the algorithm.

The LINE number where an error was found.

Error messages to read

Source code editor

Page 35: Small Basic Calculator Apps lesson

Code debugging exercises 11. Type the codes and do not copy directly into your Small Basic source code editor.2. Read the comments to find out what each line of code is meant to calculate.3. Retype the correct commands, formulas or algorithm.4. Use F5 or RUN button to test and see if the source can now create an app screen

TextWindow.Write("Type a number to know the 2nd power:") ‘displays text

square = TextWindow.ReadNumber() app ask for number

TextWindow.Write("The square of the number:") ‘displays text in quote

TextWindow.Writeline(Math.Power(square,2)) displays the the 2nd power

TextWindow.Write("Type a number to know the fourth power:") ‘displays text

fourthpower = TextWindow.ReadNumber() ‘to type a number

TextWindow.Write("The fourth power of the number:") ‘displays text in quote

TextWindow.Writeline(Math.Power(square,1)) ‘displays fourth power of number

1 2

Page 36: Small Basic Calculator Apps lesson

Code debugging exercises 2 1. Type the codes and do not copy directly into your Small Basic source code editor.2. Read the comments to find out what the code is meant to calculate.3. Retype the correct commands, formulas or algorithm.4. Use F5 or RUN button to test and see if the source can now create an app screen

TextWindow.WriteLine("A app to add two numbers") ‘to display text in quote

Write("Type the first number we call A:") ‘to display text in quotefirstnumber = TextWindow.ReadNumber() ‘app asks for number

TextWindow.Write("Type the second number we call X:") ‘to display text in quotesecondnumber = TextWindow.ReadNumber()

addingnumbers = firstnumber + secondnumber

TextWindow.Write("Addition of the two numbers:") ‘to display text in quoteTextWindow.Writeline(addingnumbers) ‘to display text in quote

TextWindow.WriteLine("A program to multiply two numbers") ‘to display text

firstnumber = TextWindow.ReadNumber() ‘to get 1st number

secondnumber = TextWindow.ReadNumber() ‘to get 2nd number

multiplynum = firstnumber + secondnumber ‘to multiply 1st & 2nd number

TextWindow.WriteLine(multiplynum) ‘to display the answer

1 2

Page 37: Small Basic Calculator Apps lesson

Remember to:1. Always SAVE your source code after each update you make.2. Use the PUBLISH button on the toolbar menu to share your source codes.3. Use the above samples as an example to add details to code before publishing (Update button).4. Test your calculator app(s) to see how well it solves some math exercises in your math text book.

Reminder…

2

Small Basic Calculator Apps challenge. “The purpose of your program” . #sbcalculatorapps

adding 3 numbers formula by “YOURNAME”

Math (Algorithms)

Use the samples when publishing your source code.

Small Basic Calculator Apps challenge. “The purpose of your program”. #sbcalculatorapps

YOUR NAME e.g Gates B. NAME of your Teacher e.g Mrs Barnes classNAME of your school e.g City HighState & Country e.g Lagos, Nigeria

1

Page 38: Small Basic Calculator Apps lesson

Congratulations you can now use Small Basic to

program Math formulas.

Page 39: Small Basic Calculator Apps lesson

Let the games begin!