[英]Selections (Turing)
I am learning Turing right now. 我正在学习图灵。 We are currently making a program about having input three marks, get the two highest marks, then find the average of the two marks.
我们目前正在制作一个程序,要输入三个标记,获得两个最高标记,然后找到两个标记的平均值。 I did the code right, but it's very long and not efficient at all.
我正确地编写了代码,但是它很长而且根本没有效率。 I need a way to shorten this code:
我需要一种缩短此代码的方法:
%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
I need a way to shorten the process part without using and/or (Because that's what our teacher said). 我需要一种无需使用和/或就可以缩短过程部分的方法(因为这就是我们老师所说的)。
尝试使用数组,然后对其进行排序 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.