2

我现在正在学习图灵。我们目前正在制作一个程序,输入三个分数,得到两个最高分,然后求两个分数的平均值。我的代码是正确的,但它很长而且根本没有效率。我需要一种方法来缩短此代码:

%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

我需要一种方法来缩短流程部分而不使用和/或(因为这是我们老师所说的)。

4

1 回答 1

0

尝试使用数组,然后对其进行排序

于 2018-04-10T20:51:38.163 回答