Download presentation
Presentation is loading. Please wait.
Published byPreston Burke Modified over 8 years ago
1
Variables and Math in Code
2
Variables A variable is a storage block for information in your program “A” 011010 “A” Computer Program Memory Computer Program
3
Types of variables Different types of data require different types of “boxes” (variables). The main variable types we are going to use are: –Integer - for whole numbers eg. 1; 334; -3 –Double(float) – for decimal points eg. 1.2; 34.5 –String – for text or words eg. “hello” “s” –Boolean – for yes/no eg. True/False
4
Example of Variables Have a look at the following code examples: string Myname; Myname = “Bob”; Messagebox.show This would display a message with the text “Bob” in it. Alternatively you could have written: String Myname = Bob; To create and assign a value to the variable in one step. Have a look at the following website for more help on this concept: http://www.java2s.com/Tutorial/CSharp/0020__Language-Basics/Defineandassignvaluetovariables.htm The variable creation The variable assignment Using the variable
5
Maths in Code Maths in code is easy!! Plus = + Minus = - Multiply = * Divide = / Eg. Int mynumber = 1 + 2;
6
An example in code Create a new small program and add a button to the form. Then add the following code: int Number1; int Number2; int myTotal; Number1 = 3; Number2 = 6; myTotal = Number1 + Number2; messagebox.show(myTotal.ToString());
7
Your Turn! With all this new knowledge see if you can make your own simple calculator! (see programming task online…)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.