2

我现在正在上计算机科学课,我只是不知道如何将 3 分的平均值转换为字母等级。起初我以为我可以做类似的事情:

PRINT name$(c); TAB(6) ; USING("###.#", average(c))

作为:

PRINT name$(c); TAB(6) ; USING("***something for text here***", average(c))

但是在我在互联网上搜索和搜索之后,我一无所获。过了一会儿,我重写了我的大部分代码,但它仍然不能正常工作。有人能告诉我我能做些什么来让它工作吗?

这里是:

dim names(20)
dim average$(20)
x = 0
input "Please input Teacher's name:"; teacher$
rem teacher$
cls
input "Input student's name:"; studentname$
do while studentname$ <> ""
name$(x)=studentname$
rem name$(x)
input "Input first number:"; e
input "Input second number:"; f
input "Input third number:"; g
avg$=(e+f+g)/3
average(x)= avg
x=x+1
cls
input "Input the next name or press enter to finish:"; studentname$
loop
print teacher$; "'s Class Report"
for c = 1 to X
if (avg$>89 and avg$<101) then let avg= "A" else if
if (avg$>79 and avg$<89) then let avg= "B" else if
if (avg$>69 and avg$<79) then let avg= "C" else if
if (avg$>59 and avg$<69) then let avg= "D" else if
if (avg$<59) then let avg= "F"; print names(c), TAB(6) average$(c)
next c
end
4

3 回答 3

0

这里要注意三件事。

首先,美元符号$仅用于包含文本值而非数值的变量名的末尾。所以它是a$ = "hello"等等i = (12+34+56) / 3

其次,在输入部分计算平均值并将其存储在变量中avg$。然后在要打印字母等级的 for 循环中检查相同的变量名称。但是,您从未avg$在该 for 循环中进行设置,因此它始终只包含最后计算的值。而且它应该没有,$因为它是一个数值。

最后,就像 Shawn Mehan 已经评论的那样,您应该重命名变量以更好地反映它们的用途。这可能会消除一些混乱。因此dim avgpoint(20),对于 0-100 的分数,avgletter$="A"等等。对于字母等级。

因此,要将这些东西结合起来,我会将您的代码更改为以下内容:

input "Input first grade number (0-100):"; grade1
input "Input second grade number (0-100):"; grade2
input "Input third grade number (0-100):"; grade3
calcavg = (grade1+grade2+grade3)/3
avgpoint(x) = calcavg

接着

for c = 1 to x
    p = avgpoint(x)
    if (p>89 and p<=101) then let avgletter$ = "A"
    'etc.
于 2015-10-15T08:48:51.160 回答
0

以下是成绩报告程序的一些编码示例:

DIM Names(20) AS STRING
DIM Average(20) AS SINGLE
INPUT "Please input Teacher's name"; Teacher$
PRINT "Enter up to 20 names, <enter> to quit:"
DO UNTIL x = 20
    PRINT "Input student"; x + 1; "name";
    INPUT StudentName$
    IF StudentName$ = "" THEN EXIT DO
    x = x + 1: Names(x) = StudentName$
    INPUT "Input first number"; J
    INPUT "Input second number"; K
    INPUT "Input third number"; L
    Average(x) = (J + K + L) / 3
LOOP
PRINT Teacher$; "'s Class Report"
FOR c = 1 TO x
    SELECT CASE Average(c)
        CASE 0 TO 59
            Grade$ = "F"
        CASE 60 TO 69
            Grade$ = "D"
        CASE 70 TO 79
            Grade$ = "C"
        CASE 80 TO 89
            Grade$ = "B"
        CASE ELSE
            Grade$ = "A"
    END SELECT
    PRINT Names(c); SPC(6); Grade$
NEXT
END
于 2018-09-09T02:25:09.480 回答
0

具有可变分数的成绩报告程序的另一个编码示例:

DIM Names(20) AS STRING
DIM Average(20) AS SINGLE
INPUT "Please input Teacher's name"; Teacher$
PRINT "Enter up to 20 names, <enter> to quit:"
DO UNTIL x = 20
    PRINT "Input student"; x + 1; "name";
    INPUT StudentName$
    IF StudentName$ = "" THEN EXIT DO
    x = x + 1: Names(x) = StudentName$
    y = 0 ' number of scores
    z = 0 ' total of scores
    PRINT "Enter scores, <enter> to quit:"
    DO
        PRINT "Enter score"; y + 1;
        INPUT I$
        IF I$ = "" THEN EXIT DO
        IF VAL(I$) >= 0 AND VAL(I$) <= 100 THEN
            y = y + 1
            z = z + VAL(I$)
        ELSE
            PRINT "Value must be 0 to 100."
        END IF
    LOOP
    IF y > 0 THEN ' avoid division by zero
        Average(x) = z / y
    END IF
LOOP
PRINT Teacher$; "'s Class Report"
FOR c = 1 TO x
    SELECT CASE Average(c)
        CASE 0 TO 59
            Grade$ = "F"
        CASE 60 TO 69
            Grade$ = "D"
        CASE 70 TO 79
            Grade$ = "C"
        CASE 80 TO 89
            Grade$ = "B"
        CASE ELSE
            Grade$ = "A"
    END SELECT
    PRINT Names(c); SPC(6); Grade$
NEXT
END
于 2018-09-09T02:55:59.360 回答