MedVision ad

Pseuodocode Help (1 Viewer)

amsv_1

New Member
Joined
Mar 7, 2022
Messages
2
Gender
Male
HSC
2023
Im blanking rn and don't know how to do this question with pseuodocode

Create an algorithm that calculates the average of a series of numbers.
 

dasfas

Well-Known Member
Joined
Dec 17, 2019
Messages
469
Gender
Male
HSC
2019
sorry if this isn't helpful (i don't know how to write in the pseudocode that SDD requires well but)

a series would probably be an array, then use a FOR loop to add each item in that array, and divide by array length?
(i'll try write it in the pseudocode NESA provides but this is quite literally my first try o_O)
BEGIN AVERAGECALCULATOR read(series)
let seriesLength = 0
let total = 0
REPEAT
get seriesitem
total += seriesitem
seriesLength +=1
UNTIL end of series
output total/seriesLength
END AVERAGECALCULATOR

(sorry if this isn't really good, just wanted to give it a try)
(edit: tried to make it better??? also sorry for terrible indentation)
Looks good, the only thing I would add when actually implementing this would be to make sure that the calculated average uses float division, not integer division.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top