我现在正在学习图灵。我们目前正在制作一个关于输入三个标记的程序,获得两个最高分,然后找到两个标记的平均值。我做的代码是正确的,但它很长并且根本没有效率。我需要一种方法来缩短这段代码:
%Variables and Contants
var rfirstmark : real
var rsecondmark : real
var rthirdmark : real
var rfirsthigh : real
var rsecondhigh : real
var rthirdhigh : real
var raverage : real
const camount := 2
%Input
put "Enter the first mark."
get rfirstmark
put ""
put "Enter the second mark."
get rsecondmark
put ""
put "Enter the third mark."
get rthirdmark
put ""
%Process
if rfirstmark > rsecondmark then
if rfirstmark > rthirdmark then
rfirsthigh := rfirstmark
end if
end if
if rfirstmark > rthirdmark then
if rfirstmark > rsecondmark then
rfirsthigh := rfirstmark
end if
end if
if rfirstmark < rsecondmark then
if rfirstmark > rthirdmark then
rsecondhigh := rfirstmark
end if
end if
if rfirstmark < rthirdmark then
if rfirstmark > rsecondmark then
rsecondhigh := rfirstmark
end if
end if
if rfirstmark < rsecondmark then
if rfirstmark < rthirdmark then
rthirdhigh := rfirstmark
end if
end if
if rfirstmark < rthirdmark then
if rfirstmark < rsecondmark then
rthirdhigh := rfirstmark
end if
end if
if rsecondmark > rfirstmark then
if rsecondmark > rthirdmark then
rfirsthigh := rsecondmark
end if
end if
if rsecondmark > rthirdmark then
if rsecondmark > rfirstmark then
rfirsthigh := rsecondmark
end if
end if
if rsecondmark < rfirstmark then
if rsecondmark > rthirdmark then
rsecondhigh := rsecondmark
end if
end if
if rsecondmark < rthirdmark then
if rsecondmark > rfirstmark then
rsecondhigh := rsecondmark
end if
end if
if rsecondmark < rfirstmark then
if rsecondmark < rthirdmark then
rthirdhigh := rsecondmark
end if
end if
if rsecondmark < rthirdmark then
if rsecondmark < rfirstmark then
rthirdhigh := rsecondmark
end if
end if
if rthirdmark > rfirstmark then
if rthirdmark > rsecondmark then
rfirsthigh := rthirdmark
end if
end if
if rthirdmark > rsecondmark then
if rthirdmark > rfirstmark then
rfirsthigh := rthirdmark
end if
end if
if rthirdmark < rfirstmark then
if rthirdmark > rsecondmark then
rsecondhigh := rthirdmark
end if
end if
if rthirdmark < rsecondmark then
if rthirdmark > rfirstmark then
rsecondhigh := rthirdmark
end if
end if
if rthirdmark < rfirstmark then
if rthirdmark < rsecondmark then
rthirdhigh := rthirdmark
end if
end if
if rthirdmark < rsecondmark then
if rthirdmark < rfirstmark then
rthirdhigh := rthirdmark
end if
end if
raverage := (rfirsthigh + rsecondhigh) / camount
%Output
put "The average of the two highest marks is " ..
put raverage
我需要一种方法来缩短过程部分而不使用和/或(因为这就是我们老师所说的)。