To get started in programming i'm going to teach you a few concepts so that you can understand how a computer understands. Not all the words that follow will be proper programming because i will use pseudo code which is a mix of programming and English.
Enough waffle, let the programming commence.
Excercise 1 - Calculate an average
You are asked by the English teacher to calculate the average score of her class of English students for the year and to indicate if the student passed or failed.
There are 10 students in the class and each student wrote 7 tests during the year. She has provided you with a list of 10 names and the score each one received for their tests.
The teacher has given you a Spec or specification of what she expected the output of the program you will write, it is also called the requirement. You cannot write a program without a spec, the user has to have so sort of requirement else there is no point in writing a program
She has also provided you with data, or input, this is the information that will be provided to the program in order to generate the outcome the teacher required in the spec.
Ok. Time to think methodically. How are we going to do this? How do you calculate an average? Add up the scores and divide. Lets look at the first name of the list.
Andrew 70,80,80,75,85,80,82
That is the students name and the 7 scores he obtained for the 7 tests he wrote.
How is this turned into a computer program?
Well lets look at the steps that you do if you were to do this yourself.
You know that to calculate an average you have to add all the various scores and divide, so lets do that. Take your calculator and add 70 + 80 + 80 + 75 + 85 + 80 + 82
Hang on.
What where you probably saying, while you did that?
Didn't you in your mind say "add 70, add 80 , add 80 , add 75, add 85, add 80 add 82" ?