It 210 Week 4 Check Point 1

Only available on StudyMode
  • Download(s) : 99
  • Published : April 16, 2013
Open Document
Text Preview
1 Declare CountAge As Integer
2 Declare SumAge As Float
3 Declare Age As Float
4 Declare ParticipantAverage As Float
5 Set CountAge – 0
6 Set SumAge – 0
7 Write “Enter one age. Enter 0 when done.”
8 Input Age
9 While Age > 0
10 Set CountAge = CountAge + 1
11 Set SumAge = SumAge + Age
12 Write “Enter an participant age. Enter 0 when done.” 13 Input Age
14 End While
15 Set ParticipantAverage = SumAge / CountAge
16 Write “Your age average is “ + AgeAverage

* Lines 1–6 declare and initialize the variables.
* Line 7 asks for the first age and also explains that when you are finished entering the age for a particular set, you can end by entering 0.
* The first Age is input on line 8.
* Lines 9–14 are the loop. It sums the age entered and it keeps count of how many ages were entered.
* In Line 10 keeps track of how many ages are entered. For each pass through the loop, CountAge is incremented by 1. If you enter three ages before you end the program by entering 0, the loop will execute three times and CountAge will be equal to 3. If you enter 5 ages, the loop will execute 5 times and CountAge will be equal to 5.

* Line 11 keeps a sum of all the participant ages. To compute your participant average age, you must divide the sum of all your participants ages by the number of participants, so lines 10 and 11 keep track of the information we need to compute the average at the end. * Lines 12 and 13 ask the user for the next participants age and gets the next input. Here, if you’re done, you can enter a 0.

* Line 14 ends the loop when the user enters a zero.
* Line 15 computes the average and line 16 displays that average.
tracking img