Once we've mastered how to actually put writing on a screen, the next difficult part is to actually make your program more useful than just typing on an ancient word processor.
Understanding Variables
Variables are the answer to how we can make our program become more useful. A variable is just another scary word for a category. Imagine on a survey or a form where you have to state something next to a category. (First name? Last name?) In order for your programming platform to understand what to do with pieces of information, you need to tell it that these pieces of information that users are entering belong to a certain category. There are different types of categories that store certain types of input from users.
This lesson focuses on the "string" variable.
String is the category type that tells the platform that users are putting in words into the field.
This lesson focuses on the "string" variable.
String is the category type that tells the platform that users are putting in words into the field.
Step 2: IF THEN ELSE
This is where we can get fancy and also let your creative juices flow. You may play around with an optional command in your program that lets you change your text color. But the big thing about this program is learning about one of the fundamentals of the IF/THEN/ELSE statement. To understand how to do this section will require you to think of a ham sandwich analogy. (If you don't understand this or if you missed this class, come see me for additional help). |
Picture a sandwich--your top slice of bread is the "begin" command and the bottom slice is the "end" command. All the juicy bits that spice up this sandwich--in this case the sandwich is your program--are in the middle.
When you are giving users a choice to answer your questions, the outcome is either this or that. In programming language, we use the commands IF something happens THEN do [this], ELSE (otherwise) do [that].
The thing about ancient programming language in Turbo Pascal is that to offer this sort of a choice question you need to have a separate begin and end commands to tell the platform to do [this] or do [that] separately.
This is where SYNTAX and FORM becomes a very important factor in making sure your program runs smoothly. Notice how in the image above, that the syntax in the first begin and end sandwich has no punctuation at the end--this signifies to the platform that your big if/then/else command is not finished just yet--when you do finish with your other option's command, the end statement concludes with a semicolon.
When you have multiple commands that start with the same word, it helps a lot with the FORM of how the program is written by INDENTING certain parts to make the "sandwich" more visible and help organize the information better. This way you have a clearer visual on what is happening and can help you identify where the error is faster.
The final end command (not shown in the image above) concludes with a period after to signify to the platform that your program is now finished completely.
When you are giving users a choice to answer your questions, the outcome is either this or that. In programming language, we use the commands IF something happens THEN do [this], ELSE (otherwise) do [that].
The thing about ancient programming language in Turbo Pascal is that to offer this sort of a choice question you need to have a separate begin and end commands to tell the platform to do [this] or do [that] separately.
This is where SYNTAX and FORM becomes a very important factor in making sure your program runs smoothly. Notice how in the image above, that the syntax in the first begin and end sandwich has no punctuation at the end--this signifies to the platform that your big if/then/else command is not finished just yet--when you do finish with your other option's command, the end statement concludes with a semicolon.
When you have multiple commands that start with the same word, it helps a lot with the FORM of how the program is written by INDENTING certain parts to make the "sandwich" more visible and help organize the information better. This way you have a clearer visual on what is happening and can help you identify where the error is faster.
The final end command (not shown in the image above) concludes with a period after to signify to the platform that your program is now finished completely.
Assignment #2:
Create a program that asks the users 10 survey questions. Your questions must be ones that offer users a choice when answering them. Depending on how the user answers, you must include an outcome/comment that responds back to what the choice was.
Out of 14 marks. 10 marks for 10 questions. 1 mark for each skill checked off on the skills mastery list. |
Skills Mastery List:
|