Saturday, August 31, 2019
It 210 Week 4 Check Point 1
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 befor e 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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment