App Programming‎ > ‎

Basic Calculation Apps

Basic Calculation Apps

If you have not already created a program to put on your Android device, go to: Calc Programs to make one

This is the one we made:

            

You enter 2 numbers, press the "Done" button and it calculates the sum and product of the 2 numbers

                  



Calculator Programs
We use computers because they do complicated calculations and solve problems very quickly. Here we will get some practice using the computer to solve problems for us.

We can create PC or Mac "Standalone" programs that do NOT need to have LiveCode installed on the computer to run it. We can also create a version to put on our smart phones

A Simple Calculator - Magic Math

Create a simple program that will do some math for us. The user will give us 2 numbers, we will save those numbers in variables and then do some math with them. Afterwards, you will write a program of your own.

Practice - Do the following program yourself:

In the graphic below, we get two numbers from the user - Number 1 (field "num 1")  and Number 2 (field "num 2"): then we give them those numbers added together and multiplied together
The following code is on the "Done" button: (It gets the numbers that they typed in and saves them as "x" and "y". Then it puts the "sum" and the "product" of those numbers back on the screen

            on mouseUp
                put field "num 1" into x
                put field "num 2" into y
                put x+y into field "sum"
                put x*y into field "product"
            end mouseUp

When they press the "Done" button they get the answers



For a simple exercise, implement the above program 

Create a new mainstack and using label fields and text entry fields create the following:

Now we will set up the text entry field the way we want it:
        1. drag one corner to make it square and larger
        2. Name it "num1"
        3. In the "text Formating" set the size to be "24"

...to finish

Add a "Reset" Button
You may want to add a "reset" button to clear out all the fields Now to see if you understand how to do it with the following code:

on mouseUp
   put empty into field "num 1" 
   put empty into field "num 2"
   put empty into field "sum"
   put empty into field "product"
end mouseUp

Finally, add Multiply and Divide (product and division of the 2 numbers)

Now to see if you understand what we just did - add the result of subtracting and dividing the two numbers to the screen



Projects - Try it yourself:
These are small projects that you can do that involve pulling data from the screen, doing some calculations, then putting the answer back on the screen. Try a couple for practice, or any other that you can think of. You may end up with some very useful programs that you can use on your computer or later on, put them on your cellphone.


1. Calculate the area and perimeter of a rectangle (or  triangle, circle, or more than one of them)
    You type in the length and width and the program will calculate the area and perimeter of the rectangle

              
   
              


2. Change calculator.
    You type in the cost of the item and the amount that you will pay and the program will calculate the change that you will get back.

                 


3. Sales Tax Calculator
    You type in the price of the item and the program gives you the amount of tax due and the total.

                  


4. Tip Calculator
    You type in the bill and the computer gives you the amount of the tip at 5%, 10%, 15% and 20%

              


5. Euro Converter
    You type the amount in USD (U.S. Dollars) and the program converts it to Euros

                              
                        
 
note: If you do money programs, you might need to use the "round" command. (Click on the "Dictionary" icon and look it up to see how to do it)


6. Age Calculator
    You type your age in years and it tells you how old you are in months

                      


7. Height Calculator
    You type in your height in feet and inches and the program tells you your height in inches
    You type in your height in feet and inches and the program tells you your height in meters
    You type in your height in feet and inches and the program tells you your height in centimeters


8. Time Calculator
    You type in the number of days and the program tells the number of hours, minutes, and seconds that it is.

                      


9. Weight/Units Calculator
    You type in your weight in pounds and calculate it in Kilograms.

                  


10. Other Programs involving calculations

                      



   

Comments