Please don't laugh at my newbieness, this is an 11th grade CS assignment. Constructive feedback would be higly appreciated
Ok, so I have an assignement due for next week. It's fairly straight forward.
Task 1
A school keeps records of the weights of each pupil. The weight, in kilograms, of each pupil is recorded on the first day of term. Input and store the weights and names recorded for a class of 30 pupils you must store the weights in a one-dimensional array and the names in another one-dimensional array. All the weights must be validated on entry and any invalid weights rejected. You must decide your own validation rules. You may assume that the pupils’ names are unique. Out put the names and weights of the pupils in the class.
Task 2
The weights, in kilograms, of each pupil are recorded again on the last day of term. Calculate and store the difference in weights for each pupil.
Task 3
For those pupils who have a difference in weight of more than 2.5 kilograms, output, with a suitable message, the pupil’s name, the difference in weight and whether this is a rise of a fall.
My pathetic attempt. (Please note that the syntax doesn't matter that much, this is pre-highschool stuff, some elements of my code are slightly VB-like)
Task 1
dim Studentnames[1:30] as string
dim Studentweights[1:30] as integer
For count=1 to 30
Input name
name = studentname[count]
Input weight
If weight>100 OR weight<20
THEN PRINT "ERROR: Weight not within range"
Else weight1 = studentweight[count]
Output studentweight[count], studentnames[count]
next
endfor
Task 2
dim weightdiff[1:30] as integer
dim diff as integer= 0
For count= 1 to 30
Input studentweights[count], finalweight
diff= studentweights[count] - finalweight
diff= weightdiff[count]
next
end for
Task 3
dim loss as integer= 0
dim gain as integer=0
For count = 1 to 30
Input studentname[count], weightdiff[count]
If weightdiff[count] >2.5
THEN gain= weightdiff[count]
PRINT studentname[count], "has lost", loss, "kilograms of weight"
Else if weightdiff[count] <2.5
THEN loss= 0 - weightdiff[count]
PRINT studentname[count], "has gained", gain, "kilograms of weight"
next
endfor
Since a negative weightdiff means a gain in weight, I subtracted the weightdiff from 0 (to make it positive) and then stored it in a variable called gain.